You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kmussel edited this page Dec 15, 2010
·
6 revisions
CoreJS offers the ability to easily create a TCP socket server with asynchronous callbacks.
Before any clients can connect to a server we need to create a socket to listen and accept connections on a given port.
Create Server:
// Create Server Object this will automatically start listening on the port and accept incoming connections:varserver=newserverSocket(PORT);// On Client Connection: callback triggered when a client connects to the server:server.onConnect(function(data){print("Client has connected. ");});// On Client Disconnectserver.onDisconnect(function(data){print("Client has disconnected. ");});// Receiving Data: Callback used when server receives data from the clientserver.onData(function(data){print("Data received from client= "+data);});
Create Client:
// Create Client Object: this will connect to the the server if there is a running server listening for connections/*** HOST: string* PORT: int**/varclient=newclientSocket(HOST,PORT);// Receiving Data: Callback triggered when client receives data from the serverclient.onData(function(data){print("Data receieved from server= "+data);});