I build tcp server socket and client and i send message from server to client and vice versa and it is running without any problem .But i want to chat between two client .what is the best way and steps to do that. (local network)
Asked
Active
Viewed 358 times
-1
-
Please add the code you already have – Abdelhak Nov 19 '15 at 00:12
-
Two clients?... you need someone that connects and someone that accept connection... 2 that like to connect with none accepting seems difficult... maybe include some server behavior in the client?, or the server stores the messages from the different clients and send it to them... – Petter Friberg Nov 19 '15 at 00:16
-
Possible duplicate of [Connect two client sockets](http://stackoverflow.com/questions/2578254/connect-two-client-sockets) – Petter Friberg Nov 19 '15 at 00:16
-
2 clients that connect to 1 server? So server needs to relay all messages from all clients to all the other clients. Question is, how did you implement your server? Separate read & write threads per client? Or nonblocking even? Do you have some sort of message queue to enqueue messages to clients? Or in an event based system a global message bus? – zapl Nov 19 '15 at 00:21
1 Answers
1
You cannot connect a client socket to a client socket - however, you can use one of the following models:
- One 'client' uses a ServerSocket, while another client uses a Socket, and connects the the ServerSocket
- Someone (can be one of the clients) runs a server application which all clients connect to. The server relays messages in between the clients