0

I have seen a lot of tutorials on client/server chat rooms using sockets, I am trying to create a instant messenger which will allow users (stored in a sql db) to chat with there contacts and groups(also stored on sql db). now I am really puzzled where to start. how would i go about creating a server which can handle peer to peer chat and group chat. I am using a mysql database which will store the user data and contacts list.

2 Answers2

0

To get you started on ServerSocket and ClientSockets for multiple clients you can refer to the below post. Two Socket sharing a port

Ideally every client would have only 1 socket connection to the server. To differentiate between your chats you can very simply use a unique identifier which will help differentiate between the different chat types.

Community
  • 1
  • 1
AdityaKeyal
  • 1,208
  • 8
  • 14
  • thanks for the reply, so do you mean that ever client would have a socket each which would connect to ONE socket in the server or will the server have to have a socket for each client socket. – user3252991 Apr 25 '14 at 12:20
  • The Server would have 1 `ServerSocket`. Multiple clients (each with a `Socket` of their own) would connect to the same `ServerSocket` in the server. – AdityaKeyal Apr 25 '14 at 12:22
0

You will need to create a multi-threaded socket server, this will accept incoming connections on a loop, and then pass off all operation between that instance of the socket and the client into a separate thread. This will allow you to run multiple client connections at once. This Page goes into great detail about creating both single and multi-threaded chat servers.

Lex Webb
  • 2,772
  • 2
  • 21
  • 36