Re: MSDN Using Asynchronous Server Socket ?



Micheal Thanks,
I properly shutdown the socket after receiving the message.
socket.Shutdown(ShutdownType.Both);
socket.Close();


"Michael D. Ober" wrote:


The problem is in your server code that handles the active connection. The
framework doesn't handle a lot of "idle" connections very well. When your
client disconnects, do you shutdown and then close the client socket?

Mike Ober.


"Zeeshan Gulzar" <ZeeshanGulzar@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7E8E4EB8-3CB6-40E5-96FE-40B1F0081715@xxxxxxxxxxxxxxxx
I am using MSDN Sample Code of "Using Asynchronous Server Socket (C#)" in
a
windows service running
under Local System Account named Listener Service.

Client Code is also Asynchronous(C#) and embed in Windows Service running
under Local System Account
named Dispatcher Service.

This service works as follows:

1. Get message from Message Queue (MSMQ)
2. Connect to server at port 4000 (This machine is connected with server
machine via Modem
Both Start "Routing and Remote Access Service" just before Listener &
Dispatcher Services starts).
3. Send Message to server and close the socket immediately (Not set Linger
option. default setting used)
4. When client connected with server, server get Socket from ENDAccept(),
store in State class etc.
(Complete code is from MSDN Sample Code mentioned above.)
5. Server Received the message and close the socket immediately (Default
Setting of socket is used).

Problem is here:

After about an hour, server reject to accept new sockets. Netstat -a -p
tcp
shows the port 4000 is in
listening state. Client receive Error WSACONNREFUSED.

One thing is that according to MSDN, this problem (Client received
WSACONNREFUSED while server is listening)
occured due to queue of the server is full (backlog). I set backlog of the
socket with 10 using
"socket.listen(10);". But why queue is full, because i receive message
from
socket and close it immediately
so this sould returned back to queue. I increase this value to 100 instead
of 10 but problem is still there.
I am using Windows Server 2000.

Is this is the problem of TIME_WAIT. There is no entry of
TcpTimedWaitDelay
in my registry.
Accoring to MSDN, this entry exist at
HKEY_LOCAL_MACHINE\System\CurrectControlSet\services\Tcpip\Parameters
Please help me in this regard.

Or could i cope this problem by set linger option of socket to 10 sec or
less. Please help me in this regard also.

Thanks in advance.


"Vadym Stetsyak" wrote:

Hello, Zeeshan!

How many connections must the service accept?
Are you sure that there were no exceptions in AcceptCallback?

IIRC in that example in AcceptCallback the call to BeginReceive is made.
Are there any exceptions in the BeginReceive delegate.

allDone.Set() is called after the read is completed, maybe service is
hanging on ReceiveData thus introducing deadlock for the accept thread?

ZG> Here

ZG> try {
ZG> listener.Bind(localEndPoint);
ZG> listener.Listen(100);

ZG> while (true) {
ZG> // Set the event to nonsignaled state.
ZG> allDone.Reset();

ZG> // Start an asynchronous socket to listen for
ZG> connections.
ZG> Console.WriteLine("Waiting for a connection...");
ZG> listener.BeginAccept( new
ZG> AsyncCallback(AcceptCallback),listener );
ZG> // Wait until a connection is made before
continuing.
ZG> allDone.WaitOne();
ZG> }

ZG> Why we use

ZG> ManualResetEvent allDone = new ManualResetEvent(false);

ZG> and call allDone.Reset() every time.

ZG> and why not we use AutoResetEvent instead of ManualResetEvent. So
not
ZG> call Reset method every time.

ZG> Any Reason ?.

ZG> Because when i use this code in my real application as a window
ZG> service, after some time (1 day or more) it reject to accept new
ZG> sockets but service still running. This service installed on 20
ZG> machines which is connected via modem. But the problem occured on
one
ZG> or two machines.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot





.



Relevant Pages

  • Re: Socket switch delay
    ... both at the client and at the server (and why ... would you set the send buffer size to zero on a non-overlapped ... One glaring error is your client does ... So when you use a single socket, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Network intermittently dropping the connection to shared files on server
    ... what we were using with our SBS2000 server with no problems. ... It's a small Server plus 4 Client W/S set up in one office. ... All users that have current connections to the shared files are ... We have a small network < 5 clients connected to a new Dell ...
    (microsoft.public.windows.server.sbs)
  • Re: Socket server connection test
    ... The limit is likely due to the default limit for outbound connections ... causing the client to run out of ports and therefore fail. ... I have started to test my socket server. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Locking on async calls
    ... you must synchronize the entire SendMessage routine as an atomic ... operation to prevent mixed messages from being transmitted to the server. ... You are correct that read and write on the socket do not interfere with each ... If you want to handle multiple client connections from one server object ...
    (microsoft.public.dotnet.general)
  • Re: Design issue with WinSock/GetQueuedCompletionStatus
    ... delegate that to a shutdown routine called after all worker threads ... The application I've created is a server accepting connections on a few ... different TCP/IP ports and then lets the client run different commands. ... a TCP/IP socket can be closed for 2 different reasons: ...
    (microsoft.public.win32.programmer.networks)

Loading