Fathom v0.2

component fathom.socket.tcp

This component provides APIs for communication over TCP.

Methods

Methods Returns Description
closeSocket( callback ) void static This function closes a TCP 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 TCP connection.

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 previously obtained from one of the opening functions.
getPeerIP( callback, socketid ) void static This function returns the IP address of the remote endpoint of a given TCP connection.

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 previously obtained from one of the opening functions.
openReceiveSocket( callback, port ) void static This function creates a TCP socket, binds it locally to the given port, and listens for connections.
(1) Rename to openListenSocket or some such, to avoid the impression that this socket is useful for receiving only. (2) What interface does this bind to on a multihomed host? (3) How does one accept() connections?

Parameters:

  • callback <function> The callback Fathom invokes once the operation completes. When successful, its only argument is a socket descriptor. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
  • port <integer> Port to listen on.
openSendSocket( callback, destip, destport ) void static This function creates a TCP socket and connects it to the given destination.
Rename to openConnectSocket or some such, to avoid the impression that this socket is useful for sending only.

Parameters:

  • callback <function> The callback Fathom invokes once the operation completes. When successful, its only argument is a socket descriptor. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
  • destip <string> IP address to connect to.
  • destport <integer> Port to connect to.
receive( callback, socketid ) void static This function receives data on a TCP connection.

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 received data chunk. On error, its only argument is a dictionary whose member "error" describes the problem that occurred.
  • socketid <integer> The socket handle previously obtained from one of the opening functions.
send( callback, socketid, data ) void static This function sends data over the TCP connection identified by the given socket ID.
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 send call returns.
  • socketid <integer> The socket handle previously obtained from one of the opening functions.
  • data <string> The data chunk to transmit.