Welcome to www.achex.ca Your IP is: 35.171.164.77
Achex Server

Achex WSS - DevelopServer Address and Port : ws://achex.ca:4010



Source Code : https://achex.ca/websocket_server/


Server Communication Protocol:

Json based messages ( i.e.{"[variable name]":"[variable value]"} )
User protocol Steps:
  1. Authenticate - by sending
    {"setID":"[yourID]","passwd":"[yourPass]"}

    Register to Broadcast- by sending
    {"cmd":"register_broadcast","bid":"[broadcast name]"}
    javascript example:
    var myID = 'Alex';
    var mypass = 'somepass';
    ws.send('{"setID":"' + myID + '","passwd":"' + mypass + '"}'); ws.send('{"cmd":"register_broadcast","bid":"' + name + '"}');
  2. Send Messages to Users or Services - by sending
    {"to":"[username]","[var]":["value"],["[variables]":["values"]],[etc...]} javascript example:
    var destination = 'myfriend';
    var mymessage = 'hello friend';
    ws.send('{"to":"' + destination + '","msg":"' + mymessage + '"}');
  3. Send Messages to Sessions - by sending
    {"toS":"[username]","[var]":["value"],[etc...]} javascript example:
    var session = '343';
    var mymessage = 'hello friend';
    ws.send('{"tos":"' + session + '","msg":"' + mymessage + '"}');
  4. Send "ping" or "latency" and receive a json object containing your latency (i.e. {"ltcy":"##ms"})
  5. Receive Messages containing variable "FROM":"sender's username" and "sID":"sender's session ID" which are set by the server. This way you always know who sent you the packet.

Service protocol Steps:
*Need special permission to authenticate as service - contact us
  1. Authenticate - by sending
    {"serviceID":"[service],"passwd":"[yourPass] ["idtag":"[alternate name]"]"}. ID tag alloys service to select a new name so that you can have multiple instances of the same service.
  2. Send Messages to Users or Services - by sending
    {"to":"[username]","[var]":["value"],["[variables]":["values"]],[etc...]}
  3. Send Messages to Sessions - by sending
    {"toS":"[username]","[var]":["value"],[etc...]}
  4. Send "ping" or "latency" and receive a json object containing your latency (i.e. {"ltcy":"##ms"})
  5. Receive Messages containing variable "FROM":"sender's username" and "sID":"sender's session ID" which are set by the server. This way you always know who sent you the packet.

Service - User protocol: Defined by JSON object packet data between user and service. User needs to send JSON objects containing variable "to" or "toS" with value USER or SESSIONID respectively.



Before you start, please copy this banner on your development site if you use this server.
Powered by Achex WebSocketServer
see banner code



Server Interfaces:

Javascript - websocket
Connect: var ws = new WebSocket('ws://achex.ca:4010');
Send MSG: ws.send("a sample message");
Note: You can send any string, but in order to communicate with the server, you need to follow the achex server protocol otherwise all messages will be dropped
Disconnect: ws.close();
Event Connection: ws.onopen = function(evt){ /* connect event */ };
Event Receive MSG: ws.onmessage = function(evt){ var received_message = evt.data;};
Event Error: ws.onerror = function(evt){ console.log(evt); };
Event Disconnect: ws.onclose = function(evt){ alert("Disconnected");};


C++ using Achex API - will be realeased soon as open source

Connect:
WS_Client_Connection myconnection([port#],"[serverdomain]");

Send MSG:
myconnection.ws_send([Message]);

Disconnect:
myconnection.close();

Check if Received MSG:
bool conn_has_data = myconnection.ws_incomming_data(polltimeout, *retval);

Read Received buffer:
std::queue frame_queue = myconnection.ws_recv();


Possible alternative to implement Receive MSG:
Will only have a queue with a mutex associated with it. The queue will be filled by a Receiving thread and all status and connection errors will be handled by the receiving thread also raising a flag when connection is closed.