UDP connector: Ping
Warning: This is an unstable API that is subject to change or removal at any time.
An example of writing a 'ping' message to a UDP server on localhost.
Instantiate an instance of text encoder to write to the UDP stream.
const encoder = new TextEncoder();Create a UDP listener to allow us to send a ping to the other UDP server.
const listener = Ende.listenDatagram({
port: 10001,
transport: "udp"
});Since UDP is a connectionless protocol, we need to define the address of the listener
const peerAddress: Ende.NetAddr = {
hostname: "127.0.0.1",
port: 10000,
transport: "udp"
};Encode the "ping" message and write to the UDP connection for the server to receive.
await listener.send(encoder.encode("ping"), peerAddress);
listener.close();Run this example locally using the Ende CLI:
ende run -N --unstable-net https://docs.ende.sh/examples/scripts/udp_connector.ts