Type of socket, for now this should always be udp4
This symbol shall be used to install a listener for only monitoring 'error'
events. Listeners installed using this symbol are called before the regular
'error'
listeners are called.
Installing a listener using this symbol does not change the behavior once an
'error'
event is emitted, therefore the process will still crash if no
regular 'error'
listener is installed.
Bind the socket to an ip and port.
Port
IPV4 address
Disconnect cleanly by sending a disconnect packet and waiting for a response. Otherwise the next time we try to connect the server won't respond to the hello.
Wrapper for asyncronously sending raw packets.
Data as a byte buffer
Helper for sending reliable packer. Automatically handles waiting for acknowledgements and incrementing the reliable id. https://wiki.weewoo.net/wiki/Protocol#Reliable_Packets
Type of packet to send
Data as a byte buffer
Generated using TypeDoc
Implementation of the Hazel base protocol with a raw UDP transport.
This handles things such as different packet types, as well as sending acknowledgements and pings.
No parsing is done to the inner packets to maintain separation of concerns. You should be able to use this with any Hazel-based backed without trouble.
The main methods you'll be using are:
send
andsendReliable
for sending messagesconnect
anddisconnect
for, well, connecting and disconnectingon
to listen for the message eventIn 99% of use cases you'll also want
@among-js/data
for packet type enums and more, as well asbytebuffer
for a nice buffer library.import { HazelUDPSocket } from '@among-js/hazel' import { PacketType } from '@among-js/data' import ByteBuffer from 'bytebuffer' const socket = new HazelUDPSocket('udp4') socket.on('message', (buffer) => { console.log(buffer.toDebug(true)) }) // Send an empty hello packet await socket.sendReliable(PacketType.Hello, new ByteBuffer(0))