clox: My Latest Invention

This is how clox works.
This is a Language Agnostic Chat Server…..Basically, You should take clox and write any client for it. I have successfully written chat clients for both Desktop and Mobile using clox as the server. This is an effort to simplify writing chat applications. The bulk of the Server side work has been done in clox.
The server is written in java, but you can have clients in any language you want as long they obey these protocols
  1. connect to the server (the port is 1981, make the ip address configurable since the server can be hosted anywhere)
  2. send a message to the server, the format of the message is “details:port=” + socket.getLocalPort() + “:sname=” + username + “:saddress=” + socket.getLocalAddress() + “\n”; The “:s” is a delimiter that separates the values.
  3. The server then starts sending you messages.
    • If you are just connecting, the server sends you a list of connected clients. The format is “clients:clientName1:sclientName2:sclientName3:setc\n”
    • If you already got the list of connected clients, the server keeps updating this list, so u must continually listen for incoming messages matching this format.
    • Also when someone sends you a message, you get the message in this format “message:from=sender:s” + “to=recipient:s” + “date=longvalueofdate:s” + “msg=message\n”; The “:s” is a delimiter that separates the values. The date is a long value(System.getCurrentTimeInMillis()).
    • When someone sends you a file, you get it as a stream of bytes.(a byte can easily be casted to an integer). The first thing you recieve is a filename in this format “file:filename:sport:port\n”. The “:s” is a delimiter that separates the values. This means that the server has opened a new port for you to start sending files. The new port is neccessary so that we dont congest the chat port in case the file is large. Connect to this port and start reading the bytes sent to you. All you need to do is write these bytes directly to the file you created with filename.
  4. When you want to send a message to the another client, use this format
    • “message:from=sender:s” + “to=recipient:s” + “date=longvalueofdate:s” + “msg=message\n”; The “:s” is a delimiter that separates the values. The date is a long value(System.getCurrentTimeInMillis()).
    • When you want to send a file, you do three things
      • send the filename of the file you want to send. The format is “file:filename=filename:sto=recipient\n”. You must include the name of the recipient in this command.
      • The server then sends you an “ackfile:filename=filename:sport=port\n”. This means the filename has been recieved and the server has opened a port for you to start sending the file as bytes. The new port is neccessary for reasons given in 3d. above.
      • Send the file itself to server (as bytes) through the port opened to you by the server. The server reads the bytes send and reconstruct the file on the other end
  5. Also note that the server will read messages from you until it encounters a new line. So all messages between you and the server must terminate with a newline. The server already observes this when sending messages to you.
  6. The server doesnt take care of duplicate users. Your client application should take care of that. Your client should have a log in of some sort such that only truly registered clients are sent to the server and there are no duplicates.
  7. The server has a gui for management(Starting,stopping and the likes).
  8. I also have a cloxclient project to give you a feel of what the client should look like.
    • From Server:
      • clients:csv  see 3a. aboove
      • message:msgstring see 3c. above
      • idle:fromclient, toclient
      • typing:fromclient, toclient
      • sms:fromclient, toclient, smsmessage //not yet implemented
      • file:fromclient, toclient, filename
    • To Server
      • String_clientDetails //this must be send at the point of connection. see 2 above
      • message:string //see 4 above
      • idle:fromclient,toClient
      • typing:fromclient,toClient
      • sms:fromcleint,toClient,smsmessage //not yet implemented
      • file:fromcleint,toClieint,filename

The code is open source, hosted on GITORIOUS, the URL is CloxServer and the desktop client is CloxClient

Happy Cloxing



  1. Chuk said

    Hi instead of writing a full server, have you considered layering clox on top of Jabber? The XMPP protocol is sufficiently extensible that it can carry clox message in a separate namespace. Can can write an external component to most XMPP servers to handle routing of the clox messages.

    • truth be told, I have never used Jabber, and since cisco acquired it I have had less faith in it.
      anyway, this like most of my open source projects is more of academic than actually trying to do “the next big thing”.
      sometimes later I will check on Jabber and see how easy it will be to port clox protocols to it.


RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: