Module: fathom/socket/udp

This component provides APIs for unicast communication over UDP. For multicast and broadcast options, see the respective namespaces.
Source:

Methods

(static) bind(callback, socketid, addr, port, reuse)

This function binds a UDP socket to a local IP address and port.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
addr string local IP address to bind to.
port integer Port to listen on.
reuse boolean Reuse the port.
Source:

(static) close(callback)

This function closes a UDP socket.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
Source:

(static) connect(callback, socketid, addr, port)

This function connects a UDP socket to a remote IP address and port.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
addr string IP address to connect to.
port integer Port to connect to.
Source:

(static) getHostIP(callback, socketid)

This function returns the IP address of the local endpoint of a given UDP flow.
Parameters:
Name Type Description
callback function The callback Fathom invokes either when an error has occurred or when data has arrived. When successful, its only argument is the local IP address. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle identifying the UDP flow.
Source:

(static) getPeerIP(callback, socketid)

This function returns the IP address of the remote endpoint of a given UDP flow.
Parameters:
Name Type Description
callback function The callback Fathom invokes either when an error has occurred or when data has arrived. When successful, its only argument is the remote IP address. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle identifying the UDP flow.
Source:

(static) open(callback)

This function creates a UDP socket.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. When successful, its only argument is a socket descriptor ID. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
Source:

(static) recv(callback, socketid, asstring, timeout, size)

This function receives data on a UDP socket.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. If successful, the function receives a dictionary with two members: "data" for the data actually read, and "length" for the full length of the data chunk received. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
asstring boolean Return the bytes as string (default false).
timeout integer Time to wait for the data (in ms), < 0 waits forever, 0 no wait (default).
size integer Number of bytes to read (or 0 to ignore - default).
Source:

(static) recvfrom(callback, socketid, asstring, timeout, size)

This function receives data on a UDP socket, from a specific sender.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. If successful, the function receives a dictionary with two members: "data" for the data actually read, and "length" for the full length of the data chunk received. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
asstring boolean Return the bytes as string (default false).
timeout integer Time to wait for the data (in ms), < 0 waits forever, 0 no wait (default).
size integer Number of bytes to read (or 0 to ignore - default).
Source:

(static) recvfromstart(callback, socketid, asstring, size)

This function establishes a callback to get invoked automatically whenever data arrive on a given UDP socket, from a specific sender. To stop receiving, call recvfromstop().
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. If successful, the function receives a dictionary with two members: "data" for the data actually read, and "length" for the full length of the data chunk received. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
asstring boolean Return the bytes as string (default false).
size integer Number of bytes to read (or 0 to ignore - default).
Source:

(static) recvfromstop(callback, socketid)

This function cancels the callbacks previously installed via recvfromstart().
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
Source:

(static) recvstart(callback, socketid, asstring, size)

This function establishes a callback to get invoked automatically whenever data arrive on a given UDP socket. To stop receiving, call recvstop().
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. If successful, the function receives a dictionary with two members: "data" for the data actually read, and "length" for the full length of the data chunk received. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
asstring boolean Return the bytes as string (default false).
size integer Number of bytes to read (or 0 to ignore - default).
Source:

(static) recvstop(callback, socketid)

This function cancels the callbacks previously installed via recvstart().
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
Source:

(static) send(callback, socketid, data)

This function sends data over a UDP socket.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
data string Data to send.
Source:

(static) sendrecv(callback, socketid, data, asstring, timeout, size)

This function sends data on a UDP socket and reads subsequently returned responses. This function is an optimization, saving one message-passing roundtrip into the Fathom core to read the response after having sent data.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. If successful, the function receives a dictionary with two members: "data" for the data actually read, and "length" for the full length of the data chunk received. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
data string Data to send.
asstring boolean Return the bytes as string (default false).
timeout integer Time to wait for the data (in ms), < 0 waits forever, 0 no wait (default).
size integer Number of bytes to read (or 0 to ignore - default).
Source:

(static) sendto(callback, socketid, data, ip, port)

This function sends data over a UDP socket, to a specific destination.
Parameters:
Name Type Description
callback function The callback Fathom invokes once the operation completes. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
socketid integer The socket handle previously obtained for this UDP flow.
data string Data to send.
ip string IP address to send to.
port integer Port to send to.
Source: