You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2025. It is now read-only.
Send network packets over a TCP or UDP connection.
Packet
Packet is the main class representing a single network message. It has a byte code indicating the type of the message and a []byte type payload.
Stream
A stream has a send and receive channel with a hot-swappable connection for reconnects.
The user has the responsibility to register a callback to consume errors via OnError.
Example
// Connect to a serverconn, _:=net.Dial("tcp", "localhost:7000")
// Create a streamstream:=packet.NewStream(1024)
stream.SetConnection(conn)
// Send a messagestream.Outgoing<-packet.New(0, []byte("ping"))
// Receive messagemsg:=<-stream.Incoming// Check message contentsifstring(msg.Data) !="pong"
Hot-swap example
// Close server connection to simulate server deathserver.Close()
// Send packet while server is down (will be buffered until it reconnects)client.Outgoing<-packet.New(0, []byte("ping"))
// ReconnectnewServer, _:=net.Dial("tcp", "localhost:7000")
// Hot-swap connectionclient.SetConnection(newServer)
// The previously buffered messages in the Outgoing channel will be sent now.
Style
Please take a look at the style guidelines if you'd like to make a pull request.