Search code examples
tcpwindows-cewinsocktcplistener

Limit the number of TCP connection I can acceptI() on WinCE


My requirements is "Limit the number of sockets I can accept() on WinCE, let's say 60 sockets".

Because I came across problem:

  1. My WinCE embedded system has limited resource to handle requests from TCP. So I must limit the number of TCP connections.

  2. I tried this : if I do not call accept() if I found I have already accepted 60 sockets. There would be serious problems on it. The device would become very slow. I am trying to debug this.

  3. If I first accept() it, and then close() it, client would report error; because client believes it is misbehaving if server first accepts a TCP connection and then closes it immediately.

Could any one give me a hint about how I could do this.

I tried to read source code in the /WINCE/PRIVATE folder,I can only trace to "proxy.SOMETHING()". It seems I can not find the code of windows socket. Could you please correct me if I am wrong.


Solution

  • If you don't call accept() connections are still established at the lower TCP/IP level, having the other side then waiting for your accept (and maybe then retrying). Even if you don't call accept() then you will still have some activities going on for each connection request and this may be the stuff that slows down your system. You should have a socket bound to the incoming port (and optionally address) with a listen call pending. As long as you do a listen() you are telling the system to process incoming connection requests and report them to you for an accept(). If you close that socket and don't do any listen() on it (better to close it because this will remove most of the connection management stuff) then the system load should decrease. On the other side clients will report your server as unreachable and this may be an issue because they will not be able to understand if the server is really down or just loaded by requests.