How i can make my server receive data from certain client and send it to other certain one ? (Note : there is a lot of clients connected with that server) , that's alike private chat between two clients .

There are two solutions for this ,
1) SERVER BASED (LEARN TO USE SOCKETS)
2) WEB BASED (LEARN TO USE JAVA EE)

There are two solutions for this ,
1) SERVER BASED (LEARN TO USE SOCKETS)
2) WEB BASED (LEARN TO USE JAVA EE)

yes , am already user sockets but i don't know ho i do private chat

If you want to implement private chat your system needs to be a little more complex than it already is. Obviously you can't send the message from one client to any random client, can you? The client will have to send the name of the client who needs to receive the message and the server will then send the message to that particular name. Now, this introduces another complication, how do you identify clients? That'll require some authentication procedure, however basic... So you'll have to change the client application to send it's identity too while registering with the server.

After implementing all this, you can implement private chat. In addition, if the IPs are not changing with time, one client can send the IP of another client and you can transfer the data using simple socket programming.

Cheers! :)

[EDIT: Also, you may have to keep a record (doesn't need to be serialized, because, as I said, we are speaking of chat at the very basic level) of the clients and their IPs.]

Edited 4 Years Ago by dantinkakkar: n/a

yes , am already user sockets but i don't know ho i do private chat

Hmm another method to the above, may be having the client send its messages along with a few parameters such as the user to who its too, you'd separate the two, search through the arrays which have each client that's connected -most importantly the open socket connection to the client and the username to identify the client- and find that clients unique name, or number or whatever, but as suggested rather do not use IP's... The server will then send the data to the appropriate client socket that the username was matched too...Thats what i did in mine.

[edit]However maybe it would be easier too have a client that has a server socket too and listens for connections? and thus recieves messages, you'd get the list of clients available and their IP/ports from the server. Guess there's many ways to skin a cat :P

Edited 4 Years Ago by DavidKroukamp: n/a

Hmm another method to the above, may be having the client send its messages along with a few parameters such as the user to who its too, you'd separate the two, search through the arrays which have each client that's connected -most importantly the open socket connection to the client and the username to identify the client- and find that clients unique name, or number or whatever, but as suggested rather do not use IP's... The server will then send the data to the appropriate client socket that the username was matched too...Thats what i did in mine.

[edit]However maybe it would be easier too have a client that has a server socket too and listens for connections? and thus recieves messages, you'd get the list of clients available and their IP/ports from the server. Guess there's many ways to skin a cat :P

Yeah... That's what. A simple system that just sends and receives input is not gonna work in this context. He needs to add a lot of things to it!

This article has been dead for over six months. Start a new discussion instead.