Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
tea.melonie54.xyz/snow/snowball
Small communication protocol for TCP connections
Example client:
wg := &sync.WaitGroup{}
// Resolve TCP address
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:12345")
if err != nil {
t.Fatal(err)
}
// Create snowball client
var snow *SnowballClient
snow = NewSnowballClient(wg, 3, tcpAddr, func(packet *packet.SnowballPacket) {
// Packet receiving logic only packets with `toAddr = 3` will be handled here
// Packets with `toAddr = 2` are forwarded to all clients from the server but
// the `toAddr` is changed to match to receiving client ID
switch packet.Id {
case 2:
// `MakeReply` can be used to create a packet to send back to the return address
snow.Send(packet.MakeReply(3, packet.Data))
}
})
// A WaitGroup can be used to prevent the program from closing
wg.Wait()
// Create and send a packet (with ID: 2) to client (with ID: 4)
// The from address is set to the current client
// A binary packet can be generated using a byte buffer and the functions in `net-byte-utils.go`
buf := new(bytes.Buffer)
utils.WriteString(buf, "hello")
snow.Send(NewSnowballPacketFromBytes(2, 0, 4, buf.Bytes()))
Example server:
wg := &sync.WaitGroup{}
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:12346")
if err != nil {
t.Fatal(err)
}
var snow *SnowballServer
snow = NewSnowballServer(wg, tcpAddr, func(packet *packet.SnowballPacket) {
// Packet receiving logic only packets with `toAddr = 1` will be handled here
// Packets with other addresses are automatically routed to the client
// Packets with `toAddr = 2` are forwarded to all clients automatically
switch packet.Id {
case 2:
// `MakeReply` can be used to create a packet to send back to the return address
snow.Send(packet.MakeReply(3, packet.Data))
}
})
if err != nil {
t.Fatal(err)
}
// `Serve` is non-blocking
snow.Serve()
// A WaitGroup can be used to prevent the program from closing
wg.Wait()
Packet IDs:
0x00
- Reserved for the unknown packet0x01
- Reserved for the Hello packetClient IDs:
0x00
- Reserved for the unknown client (if used as fromAddr
it is changed to the current client ID before sending)0x01
- Reserved for the server0x02
- Reserved for sending packets to all clients (can be used from the client or server Send
methods)FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.