server with multiple clients

Started by
2 comments, last by hans-ola 16 years, 11 months ago
Hej! At the moment i'm creating a turnbased game. The rules are somewhat like chess(but it's not chess). The first player roll a dice, move a brick and then it's the other players time to play. The game will also have a chat in it so you can comunicate with your oponent. I want to create a server for this, so that the first player that connects to the server will get a message "waiting for other player". When the second player enters, a game will start. When a third player enter he will get the message "waiting for other player" until the fourth player enters, and so on. This will be done by starting a new thread for every game. I'v done a chatprogram and a multiplayergame earlier, but then it was just 2 computers comunicating with each other(without server) and i had a connection open all the time. ------------------ THE PROBLEM; When 2 or more players connect to the server, is it possible for the server to have connections open for alla clients? What i understand only one socket can be open at the same time. If so, is this the best way, or should you close/open connection all the time? I'm using TCP socket programming. And the language i'm using is C#. [Edited by - hans-ola on April 21, 2007 7:57:28 PM]
Advertisement
You have a single port open listening for incoming connections on your server, when a client connects you assign it a port for direct communications. I'm afraid I can't provide any info about working with C#, but I imagine it's fairly straight forward (it was relatively easy to setup nonblocking ports in C++ when I did it a couple of years ago, so it should be a snap in C#).
On the server, you will be listening on port X. Each connection that opens up will return a new socket when you accept the connection. The server can have as many sessions open to the same port as you have memory (not quite true, but close enough).
enum Bool { True, False, FileNotFound };
Tnx guys. You helped me alot.

I will try to get this to work.

This topic is closed to new replies.

Advertisement