udp
Last updated
Was this helpful?
Last updated
Was this helpful?
(plugins.udp)
The UDP
plugin facilitates communication using UDP sockets, enabling the sending and receiving of data packets. It supports creating and manipulating custom data packets, starting and stopping sockets, and testing packet handling logic.
For creating packets, use createNewPacket
to initialize an empty packet and add data such as UTF strings, integers, or bytes. To receive data, use getReceivedPacket
, which retrieves packets from the receive buffer until it is empty. To send data, utilize sendPacket
by specifying the destination IP or hostname and an optional port. The testPacket
function allows for placing test packets in the receive buffer to validate handling methods.
Sockets can be managed using startSocket
to bind to a specific port and specify a callback method triggered when packets are received. The stopSocket
method halts the socket’s operation.
This plugin supports practical use cases like real-time data transfer and network communication testing.
,
Create a new empty packet.
Get a packet from receive buffer, read buffer until empty (null is returned).
Send a packet.
Send a packet on another port.
Start a UDP socket for a port.
void
Stop the UDP socket for a port.
Put a test packet in the receive buffer to test your method call and getReceivedPacket.
Create a new empty packet.
Sample
Get a packet from receive buffer, read buffer until empty (null is returned).
Sample
Send a packet.
Parameters
Sample
Send a packet on another port.
Parameters
Sample
Start a UDP socket for a port.
Parameters
Sample
Stop the UDP socket for a port.
Returns: void
Sample
Put a test packet in the receive buffer to test your method call and getReceivedPacket.
Parameters
Sample
Returns: a new, empty JSPacket instance for creating and sending UDP packets.
Returns: the next JSPacket from the receive buffer, or null if the buffer is empty.
destIpOrHostname the ip of the destination or the hostname
packet the JSPacket to send
Returns: true if the packet was successfully sent; otherwise, false.
destIpOrHostname the ip of the destination or the hostname
packet the JSPacket to send
port the port on which to send the packet
Returns: true if the packet was successfully sent to the specified port; otherwise, false.
port_number the local port that this UDP socket will bind to.
method_to_call_when_packet_received_and_buffer_is_empty when the socket receives one or more packages, it calls this method once. The method will no longer be called even if new packages are received - until a call to UDPProvider#js_getReceivedPacket() returns null. So you should consume all available packets before you expect this method to be called again.
Returns: true if the UDP socket was successfully started; otherwise, false.
packet ;
Returns: true if the test packet was successfully added to the receive buffer; otherwise, false.