IN JAVA, how to do a multi chat client in java with the option of private message ?
hi all
i would like to know how to do a chat client server program IN JAVA where multiple clients can connect to the server and how to be able to see a client send a private message to one of the specify client ? " the message from the client will go to the server and after will go to the specify client " at the moment i can do some private message but the message is coming from the server which is gay its working but not the good way so plz help me out with this im new to client / server application :p ty for the help ! Code:
|
Quote:
Quote:
you have given us a broad "question" and a pile of code and expect us to solve your problem. this isnt how these forums work, i dont think. please explain to us your problem, for example: Quote:
Quote:
if you are doing a central chat server, then you must define a protocol (or should already do have this, and therefore need to modify your protocol) to accept some headers/meta data, such as "this message is only supposed to go to user 1234. if it is more of a peer-to-peer architecture, then your clients dont have to change, only the one sending the private message (in which case its just like sending a normal message to all X peers (X > 1), except you only send it to the expected IP/socket/user. now, after you clear up or give us a better idea of what you are doing, please explain your problem. needless to say, im not going to go digging through your code to discover what the code is, what problem your having, and what way you want it to work. |
Quote:
Quote:
edit: if this "hybrid" architecture is what you want, then you could use the following pseudocode (client "S" is private message sender, client "R" is private message recipient, server "C" is the central chat server), this is what would happen "behind the scenes", upon S typing a private message to R and clicking "send": - S asks C to request a "private message connection" on port N for client R - C tells R to start listening on S's socket (C already must know S's IP address, and has just received the port N, so it knows the socket to tell R) - R receives this message, creates a separate thread dedicated to listening on the given socket, and replies to C that it is ready to receive the private message - C receives response "OK" from R, and tells S it is ready to send directly to R - S receives "OK" from C (which means R is ready), creates a new thread, and in this thread creates the socket on port N, sends the PM, closes the socket, kills this thread - R (in its dedicated PM thread) receives the PM, closes its read side of the socket, kills this thread R then has the message directly sent from S. |
Break it down
Well, I think you would want to stay with the client-server model, right. I mean the only way to have a message go directly from one client to another client would be to somehow re-negotiate some kind of point-to-point connection after the clients initially connected to the server. But this would require a lot more complexity, and in most practical situations won't work due to firewalls; the client usually initiates the connection out to the server.
But either way, we would want to have more of a structured message format, such as a message header, and a message body, where instead of the client currently sending the string that was typed in when the user preses enter, and the server just echoing that back to the clients, you would want to separate the user input with the construction and sending of a high level chat message. The message structure could contain a command or header information to provider the server with routing hints, such as "this message is for all", or "this message is private for a single user". And of course the message body being the string that the user typed in. For academic purposes such as our assignment, I would also recommend your custom message structure work with XML, to make it human readable, plus there are many good XML parsing API now (I would recommend having a look at StAX) to create simple XML to bean (un)marshaller code. If you wanted to get some more ideas of what is possible along these lines this, have a look into XMMP (i.e. Jabber). It is an excellent example of a real world chat protocol that has a bunch of these concepts. Their messages are also sent in an XML payload. There is even an open source Java library implementation of the XMMP (called "smack"), used in the open source Java based server and client, provided by "OpenFire". |
Hello nicolasd, did you got the private messages working?
I'm doing the same but I had some problems, can you send me your application? bmacampos@hotmail.com Thanks BC |
Go to sourceforge and download a java based chat client ... That could/should be used as ur starting point ...
:) linux |
All times are GMT -5. The time now is 05:42 PM. |