Fathom v0.2

component fathom.socket.udp

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

Methods

Methods Returns Description
bind( callback, socketid, addr, port ) void static This function binds a UDP socket to a local IP address and port.

Parameters:

  • 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 bind to.
  • port <integer> Port to listen on.
close( callback ) void static This function closes a UDP socket.

Parameters:

  • 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.
getHostIP( callback, socketid ) void static This function returns the IP address of the local endpoint of a given UDP flow.

Parameters:

  • 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.
getPeerIP( callback, socketid ) void static This function returns the IP address of the remote endpoint of a given UDP flow.

Parameters:

  • 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.
open( callback ) void static This function creates a UDP socket.

Parameters:

  • 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.
recv( callback, socketid, length ) void static This function receives data on a UDP socket.

Parameters:

  • 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.
  • length <integer> Maximum length of the data chunk to read. This is an optimization, for cases when you do not care to actually process all of the data received. To ignore this feature, pass 0.
recvfromstart( callback, socketid ) void static 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().
This function is not complete. It still needs the IP address and port we want to receive from.

Parameters:

  • 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.
recvfromstop( callback, socketid ) void static This function cancels the callbacks previously installed via recvfromstart().

Parameters:

  • 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.
recvstart( callback, socketid, length ) void static This function establishes a callback to get invoked automatically whenever data arrive on a given UDP socket. To stop receiving, call recvstop().

Parameters:

  • 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.
  • length <integer> Maximum length of the data chunk to read. This is an optimization, for cases when you do not care to actually process all of the data received. To ignore this feature, pass 0.
recvstop( callback, socketid ) void static This function cancels the callbacks previously installed via recvstart().

Parameters:

  • 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.
send( callback, socketid, data ) void static This function sends data over a UDP socket.
This function should report back the number of bytes sent successfully, and also needs error semantics.

Parameters:

  • 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.
sendrecv( callback, socketid, data, length ) void static 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:

  • 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.
  • length <integer> Maximum length of the data chunk to read. This is an optimization, for cases when you do not care to actually process all of the data received. To ignore this feature, pass 0.
sendto( callback, socketid, data, ip, port ) void static This function sends data over a UDP socket, to a specific destination.
This function should report back the number of bytes sent successfully, and also needs error semantics.

Parameters:

  • 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.
setsockopt( callback, socketid, name, value ) void static This function sets options on a given UDP socket.

Parameters:

  • callback <function> The callback Fathom invokes when the operation complets. 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.
  • name <string> The name of the option. Currently, Fathom only supports "reuseaddr".
  • value <integer> The option value. For "reuseaddr", 1 requests the option, 0 clears it.