Awesome Go

packet

CategoryNetworking
SubcategoryLibraries for working with various layers of the network.
Stars79

Send packets over TCP and UDP. It can buffer messages and hot-swap connections if needed.

About packet

packet

Godoc Report Tests Coverage Sponsor

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 server
conn, _ := net.Dial("tcp", "localhost:7000")

// Create a stream
stream := packet.NewStream(1024)
stream.SetConnection(conn)

// Send a message
stream.Outgoing <- packet.New(0, []byte("ping"))

// Receive message
msg := <-stream.Incoming

// Check message contents
if string(msg.Data) != "pong" 

Hot-swap example

// Close server connection to simulate server death
server.Close()

// Send packet while server is down (will be buffered until it reconnects)
client.Outgoing <- packet.New(0, []byte("ping"))

// Reconnect
newServer, _ := net.Dial("tcp", "localhost:7000")

// Hot-swap connection
client.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.

Sponsors

Cedric FungScott RayapoulléEduard Urbach
Cedric FungScott RayapoulléEduard Urbach

Want to see your own name here?

Frequently Asked Questions

What is packet?

packet is a Networking library for the Go programming language. Send packets over TCP and UDP. It can buffer messages and hot-swap connections if needed.

How do I install packet?

Install packet with the Go module system using `go get aerogo/packet`. Check the repository for the current installation instructions.

What category does packet belong to?

packet is listed under Networking, specifically Libraries for working with various layers of the network..

← Back to Libraries for working with various layers of the network.