Achex WSS - DevelopServer Address and Port : ws://achex.ca:4010
- QUICKSTART
- Interactive example (with Source code - javascript)
- Simple Example
- Server Communication Protocol
- WEBSOCKET TEST PAGE
Source Code : https://achex.ca/websocket_server/
Server Communication Protocol:
Json based messages ( i.e.
User protocol Steps:
Service protocol Steps:
*Need special permission to authenticate as service - contact us
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.
{"[variable name]":"[variable value]"}
)User protocol Steps:
-
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 + '"}'); - 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 + '"}'); - 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 + '"}'); - Send "ping" or "latency" and receive a json object containing your latency (i.e.
{"ltcy":"##ms"}
) - 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
- 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. - Send Messages to Users or Services - by sending
{"to":"[username]","[var]":["value"],["[variables]":["values"]],[etc...]}
- Send Messages to Sessions - by sending
{"toS":"[username]","[var]":["value"],[etc...]}
- Send "ping" or "latency" and receive a json object containing your latency (i.e.
{"ltcy":"##ms"}
) - 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.
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
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.
- Achex Game Dev
- RPG Demo
- Pong Demo
- Lets Draw Together
- Risk Demo
- Applications - Entertainment
- File Transfer between browsers
- Real-Time Multyplayer Games
- Cross Platform Games
- Data Streaming
- Chat
- Applications - Industrial
- Real-time Instrument Monitoring
- Web Interface for Instruments
- Oscilloscopes
- WebSockets - Info
- What are websockets?
- WS Applications
- Useful links