- connect to the server (the port is 1981, make the ip address configurable since the server can be hosted anywhere)
- 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.
- 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.
- 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
- 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.
- 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.
- The server has a gui for management(Starting,stopping and the likes).
- I also have a cloxclient project to give you a feel of what the client should look like.
- SUPPORTED PROTOCOLS:
- 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
- From Server:
The code is open source, hosted on GITORIOUS, the URL is CloxServer and the desktop client is CloxClient
Happy Cloxing