Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/aerogo/packet
:package: Send network packets over a TCP or UDP connection.
https://github.com/aerogo/packet
go network-programming packet tcp udp
Last synced: about 2 months ago
JSON representation
:package: Send network packets over a TCP or UDP connection.
- Host: GitHub
- URL: https://github.com/aerogo/packet
- Owner: aerogo
- License: other
- Created: 2017-10-29T05:46:44.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-20T22:35:38.000Z (about 5 years ago)
- Last Synced: 2024-05-29T00:17:52.271Z (7 months ago)
- Topics: go, network-programming, packet, tcp, udp
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 78
- Watchers: 6
- Forks: 16
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - packet - Send packets over TCP and UDP. It can buffer messages and hot-swap connections if needed. (Networking / Transliteration)
- zero-alloc-awesome-go - packet - Send packets over TCP and UDP. It can buffer messages and hot-swap connections if needed. (Networking / Transliteration)
- awesome-go - packet - Send network packets over a TCP or UDP connection. - ★ 7 (Networking)
- awesome-go-extra - packet - 10-29T05:46:44Z|2019-11-20T22:35:38Z| (Networking / Uncategorized)
- awesome-go-zh - packet
README
# packet
[![Godoc][godoc-image]][godoc-url]
[![Report][report-image]][report-url]
[![Tests][tests-image]][tests-url]
[![Coverage][coverage-image]][coverage-url]
[![Sponsor][sponsor-image]][sponsor-url]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
```go
// 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
```go
// 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](https://github.com/akyoto/quality/blob/master/STYLE.md) if you'd like to make a pull request.
## Sponsors
| [![Cedric Fung](https://avatars3.githubusercontent.com/u/2269238?s=70&v=4)](https://github.com/cedricfung) | [![Scott Rayapoullé](https://avatars3.githubusercontent.com/u/11772084?s=70&v=4)](https://github.com/soulcramer) | [![Eduard Urbach](https://avatars3.githubusercontent.com/u/438936?s=70&v=4)](https://twitter.com/eduardurbach) |
| --- | --- | --- |
| [Cedric Fung](https://github.com/cedricfung) | [Scott Rayapoullé](https://github.com/soulcramer) | [Eduard Urbach](https://eduardurbach.com) |Want to see [your own name here?](https://github.com/users/akyoto/sponsorship)
[godoc-image]: https://godoc.org/github.com/aerogo/packet?status.svg
[godoc-url]: https://godoc.org/github.com/aerogo/packet
[report-image]: https://goreportcard.com/badge/github.com/aerogo/packet
[report-url]: https://goreportcard.com/report/github.com/aerogo/packet
[tests-image]: https://cloud.drone.io/api/badges/aerogo/packet/status.svg
[tests-url]: https://cloud.drone.io/aerogo/packet
[coverage-image]: https://codecov.io/gh/aerogo/packet/graph/badge.svg
[coverage-url]: https://codecov.io/gh/aerogo/packet
[sponsor-image]: https://img.shields.io/badge/github-donate-green.svg
[sponsor-url]: https://github.com/users/akyoto/sponsorship