Creates a new thread on which to create new clients and servers.
|
Converts an array of bytes by encoding each byte into a UTF-16 character, and returns a UTF-16 string encoded from the given data.
|
Converts a UTF-16 string into an array of bytes.
|
Creates a TCP server, but does not start the server listening.
|
Creates a UDP server, but does not start the server listening.
|
Creates a TCP client.
|
Creates a UDP client.
|
createThread
method.
The API exposed to both UDP and TCP clients contain these common functions.
send(data) |
Asynchronously sends some data to the remote endpoint for this client.
|
||
sendBytes(data) |
Asynchronously sends some bytes of data across the connection.
|
||
close() |
Gracefully shuts down the client, freeing all resources once pending sends have been completed. |
||
getHost() |
Gets the hostname to which this client connects. |
||
getPort() |
Gets the port on which this client will connect to the remote host. |
The API exposed to both UDP and TCP servers contain these common functions.
listen() |
Starts up the server listening on the port given. |
close() |
Gracefully shuts down the server, freeing the port and resources once any pending sends have completed. The server will continue to listen for connections and incoming data until all pending sends have been sent. |
getPort() |
Returns the port on which this server listens. |
The API exposed to the event parameter of the data
handler function, which allows reading and sending data.
send(data) |
Asynchronously send back some data across the connection.
|
||
sendBytes(data) |
Asynchronously send back some byte data across the connection.
|
||
read() |
Read the string data that triggered this event.
|
||
readBytes(data) |
Read the bytes of the data received that triggered this event.
|
||
getHost() |
Returns the hostname from which the data was received. |
||
getPort() |
Returns the port from which the data was received on the remote host. |
The events for which we can attach Javascript event handlers to perform callbacks.
data |
This event can occur on server or clients, and is fired whenever a connection receives some data. |
error |
This event can occur on clients or server objects, and is fired whenever an unrecoverable error occurs. |
close |
This event occurs whenever a client or server completely shuts down, after the |
open |
This event occurs once a server successfully opens a new socket and begins listening for incoming connnections |
resolve |
This event occurs once a client successfully resolves the hostname of its remote endpoint |
disconnect |
This event occurs for TCP clients and servers when an error occurs that severs the TCP connection. |