WebSocket is a protocol that enables two-way persistent communication channels over TCP connections. It is used for applications such as chat, stock tickers, games, anywhere you want real-time functionality in a web application.
Use WebSockets when you need to work directly with a socket connection. For example, you might need the best possible performance for a real-time game.
First of all, read the kataras/neffos wiki to master the new websocket library built for net/http and Iris.
It comes pre-installed with Iris, however you can install it separately by executing the following shell command.
$gogetgithub.com/kataras/neffos@latest
Continue by reading how you can register the neffos websocket server into your Iris application.
For example, to gain access of the request's Context you can call the websocket.GetContext(Conn) from inside an event message handler/callback:
// GetContext returns the Iris Context from a websocket connection.funcGetContext(c*neffos.Conn)Context
To register a websocket neffos.Server to a route use the websocket.Handler function:
// IDGenerator is an iris-specific IDGenerator for new connections.typeIDGeneratorfunc(Context)string// Handler returns an Iris handler to be served in a route of an Iris application.// Accepts the neffos websocket server as its first input argument// and optionally an Iris-specific `IDGenerator` as its second one.funcHandler(s*neffos.Server,IDGenerator...IDGenerator)Handler