views:

648

answers:

3

Hi. i'm building a chat server with .net i need to know is there a limit on the number of open sockets i can have on windows 2003 server box

Also, i tried opening about 2000 client connections and my linksys WRT54GL router (with tomato firmware) drops dead each time. The same thing happens when i have several connections open on my Azureus bit-torrent client.

i need to know 3 things:

1) is there a limit on the number of open sockets i can have in windows 2003 server 2) is the linksys router the problem? if so is there better hardware recommended? 3) is there a way to possibly share sockets so that i can handle more open client connections with fewer resources.

Thanks.

Charles

+2  A: 

AS I've mentioned before, Raymond Chen has good advice on this sort of question: If you have to ask about OS limits, you're probably doing something wrong. The IP protocol only allows for a maximum of 65535 ports and many of these are reserved and not available for general use. I would suggest that your messaging protocols need to be thought out in more detail so that OS limits are not an issue. I'm sure there are many good resources describing such systems, and there are certainly people here that would have good ideas about it.

Skizz

EDIT: I'm going to put some thoughts about implementing a scalable chat server.

First off, designate a single port on the server for clients to communicate through. Whenever a client needs to update the chat state (a new user message for example) do the following:

create message packet
open port to server
send packet
close port

The server then does the following:

connection request received
get packet
close connection
process packet
for each client that requires updating
  open connection to clients
  send update packet
  close connection

When a new chat session is started, the client starting the session sends a 'new session' message to the server with the clients user details and IP address for responses. The server creates a new chat session and responds with the session ID. The client then sends packets containing the messages the user types, the server processes them and forwards the message to other clients in the same session. When a client leaves the chat, it sends a 'end session' message to the server. The server removes the client from the session and destroys the session when there are no more clients in the session.

Hope that gets you thinking.

Skizz
Skizz: thanks, but i cannot locate the relevant article from the link you provided.if i can get up to 50k from one box it is fine, can you point me to one of these good resources you have used yourself. thanks
CharlesO
The site talks a lot about system stuff and occasionally there's a comment about system limits which is usually answered with the above statement. If you need 50k connections, what's going to happen the day there's 50001 required? You need to use one connection and make it handle 50k chats.
Skizz
CharlesO
To be honest, I'm no expert on this sort of stuff. But I'm certain the one-socket-per-chat method is flawed. How does Hotmail's IM do it? They must have far more than 50K chats at once.
Skizz
Actually, it just occurred to me that the IM system can work as a peer-to-peer system where the server is used to set-up the p2p sessions, i.e. tell clients the IP address of other clients in the same session.
Skizz
Most Chat clients do have an active established connection with the server, I know this for Gtalk, they scale based on multiple servers
Dinesh Manne
Yeah, I was thinking it could scale using multiple servers, a master for initial set up which then delegates to the least loaded chat server.
Skizz
I receive all connection requests via a master server, then based on client_id i can redirect. Say svr1 handles client_id 1 to 10000, then svr2 handles client_id 10001 to 20000 etc. If i can up the number of client connections per box, i can handle more with less. That's why i'm seeking guidance.
CharlesO
skizz: your example is flawed. The server should not open connections to the users since typically they are behind firewalls. Thats why it IS relevant to keep connections open in an IM client (or to use UDP)
Toad
+2  A: 

i found this (http://smallvoid.com/article/winnt-tcpip-max-limit.html) when i was searching for similar thing for Windows XP, i think this should apply for Windows 2003

Dinesh Manne
Dinesh Manne: thanks for that link, it goes into very deep detail.
CharlesO
+2  A: 

i have found some answers to this that i feel i should share:

Windows 2003 server has a limit on the number of ports that may be used. but this is configurable via a registry tweak to change the MaxUSerPort setting from 5000 to say, 64k( max).

Exploring further, i realize that the 64k port restriction is actually per IP address, hence a single server can easily attain much more ports, and hence TCP connections by either installing multiple network cards, or binding more than one IP address to a network card. that way, you can scale your system to handle n x 64k ports.

CharlesO