Ok so this is what I have.

I have a separate code for both server and client.

Now, what I want to do is, enable the server to listen and accept connections on TWO OR MORE ports [say 5000 and 5340], thus, effectively creating two different "chat rooms". A bunch of clients communicate with each other and the server on the first port [5000], and a different bunch of clients communicate with each other, and the server on the other port [5340].

I have been able to get the server to listen and communicate on two different ports. But now, when I send a chat message from the client to the server, or from server to client, it doesn't display the message at the same time it receives it. Let me make this more clear. For example, I connect to the server on the first port. I then type two messages on the client, 'Hey' and 'Hurr Durr'. The server doesn't display anything. Now when I type 'Anyone there' on the server, it then displays 'Hey' and 'Hurr Durr' in quick succession. I think it's something to do with my for statements. I've tried to find out what exactly could the problem be for hours, and I'm drawing a blank.

Here is the server code :