a network endpoint that can initiate a connection More...
Public Member Functions | |
NetClient (object opts=null) | |
constructor for NetClient, sets client options More... | |
NetClient | connect (object serverInfo, function callback, string clientKey="") |
establish a connection to a server More... | |
NetClient | onError (function callback) |
set the callback function that will handle errors More... | |
Public Attributes | |
boolean | connection |
reference to the NetConnection, or boolean false if not yet connected More... | |
a network endpoint that can initiate a connection
NetClient is part of the PDG Engine's custom protocol for games. It handles protocol negotiation and optional connections. It establishes both a TCP connection (reliable transport with guaranteed delivery) and UDP communications (small and unreliable but fast) with the server.
NetClient doesn't actually handle network communication, it only establishes the connection. Once established, it creates NetConnection objects you can use to send and receive data.
NetClient | ( | object | opts = null | ) |
constructor for NetClient, sets client options
Construct a new NetClient with particular options or using default values if no options are specified.
Available options are:
opts | a Javascript object with the options above |
connect | ( | object | serverInfo, |
function | callback, | ||
string | clientKey = "" |
||
) |
establish a connection to a server
Attempts to connect to the given server, and if it succeeds it invokes your callback with a new NetConnection object as the parameter. The If the connection fails, you'll get an error callback if you set one up using the onError() call.
An option key is passed in to do authentication if the server requires connection reservations. See NetServer.expectClient for more about client reservations.
serverInfo | an object with host and port that tells us where to find the NetServer |
callback | the connection established handler for this connection |
clientKey | [optional] the reservation key to send to the server |
onError | ( | function | callback | ) |
set the callback function that will handle errors
This function will be called whenever a call to connect() fails. The function will be called with a single parameter, a string of the error message.
callback | the error handling function for this connection |
connection |
reference to the NetConnection, or boolean false if not yet connected