dcsimg
How to identify Client in multithreaded Server
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mangesh_Kulkarni
Posted On:   Tuesday, August 22, 2006 10:17 AM

PROBLEM Case /Situation

i have a multithreaded server which has its clients only one of them is going to write to server and that message is going to sent to all others
the client is a java file and other clients are flash sockets
now these both clients are on my Tomcat server

Please can anyone help me
i m using Handler.java file to add all clients in a Vector

Re: How to identify Client in multithreaded Server

Posted By:   Robert_Lybarger  
Posted On:   Tuesday, August 22, 2006 11:49 PM

What Tim is getting at is that you must design in some mechanism yourself to identify which client is the one sending the message(s). The exact way is really up to you. One way is via his example: make anyone who connects send a message upon their connection... the message-sending client will basically send a different message from everyone else. (Basically a secret handshake that only the server and message sender know about.) An alternate idea might be to have the message-sending client connect to the server on a different port. In either case, you need to decide if you trust the clients who are only supposed to receive messages to never lie and try to claim to be a message sending client instead. For your own hobby projects, you can ignore this, but be aware of this very important thing. I'll second his excellent recommendation to design this around plain-text communication on a standard TCP socket connection... very easy to debug, and very easy to [re]design front-end clients around w/o having to alter the backend.

Re: How to identify Client in multithreaded Server

Posted By:   Anonymous  
Posted On:   Tuesday, August 22, 2006 10:43 AM

I have no idea what Handler.java is - but if I were doing this. I'd setup a little handshake when the clients connect. The flash recievers clients would just say hello with some version or something - so you know its a good client - if they don't say hello - you should drop them. The sender client would also say hello and then send a message identifying itself as the speaker.





Client - HELO CHAT

Server - OK CHAT

Client waits for output





Client - HELO CHAT

Server - OK CHAT

Client - SET SENDER

Server - OK SENDER

Java client begins sending text



This is an quick example of a line based protocol - the advantage is you can test it over telnet.



Of course you might require a login or something. In which you would have a message for USER and PASSWD or something. Hopefully the password is encrypted if you aren't using SSL.
About | Sitemap | Contact