Skip to content

UdpServer

A localhost voice UDP server: it answers IP discovery, echoes keepalives and records every RTP packet for the test to assert on. new binds it to 127.0.0.1 with an ephemeral port and starts a receive loop that yields to the scheduler while it waits for a packet.

UdpServer.socket  :: NetworkSocket?

The Zune UDP socket, nil after the server stops.

UdpServer.port  :: number

The ephemeral port the server bound to on 127.0.0.1.

UdpServer.packets  :: { buffer }

Every RTP packet the server received, oldest first. IP discovery requests and keepalives are not recorded.

UdpServer.clientAddress  :: string?

The address the latest packet came from, nil before the first packet.

UdpServer.clientPort  :: number?

The port the latest packet came from, nil before the first packet.

UdpServer.receiving  :: boolean

True while the receive loop runs; false once stop has ended it.

UdpServer.errors  :: { string }

Every error the receive loop raised, other than the cancelled receive that stop causes and Windows' report of a client that has gone.

UdpServer.ignoreDiscovery  :: number

How many of the next IP discovery requests to drop without a reply.

UdpServer.onStop  :: function?

Called with the handle after it stops.

UdpServer.sendingThread  :: thread?

The thread whose send has the socket, nil while no send is in flight.

UdpServer.waitingSends  :: { thread }

Threads waiting for their turn to send, oldest first.

UdpServer : send ( packet )  -> ()

Sends one packet to the client the latest packet came from, after any send already in flight. Errors before any client has sent a packet or after the server stops.

Parameters

packet: buffer
UdpServer : stop ( )  -> ()

Closes the socket, which cancels the pending receive and ends the receive loop, and wakes every send waiting for its turn so it fails on the closed socket. Safe to call twice.

UdpServer . new ( settings )  -> UdpServer

Binds a UDP socket on 127.0.0.1 with an ephemeral port and starts the receive loop.

Parameters

settings: {
{ onStop: ((server: UdpServer) -> ())? } }

Returns

UdpServer