Re: MSDN Using Asynchronous Server Socket ?
- From: "Zeeshan Gulzar" <ZeeshanGulzar@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Feb 2006 09:44:31 -0800
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#)" ina
windows service runningtcp
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
shows the port 4000 is infrom
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
socket and close it immediatelyTcpTimedWaitDelay
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
in my registry.Are there any exceptions in the BeginReceive delegate.
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.
hanging on ReceiveData thus introducing deadlock for the accept thread?
allDone.Set() is called after the read is completed, maybe service is
continuing.
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
notZG> 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
oneZG> 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
ZG> or two machines.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot
- Follow-Ups:
- Re: MSDN Using Asynchronous Server Socket ?
- From: Michael D. Ober
- Re: MSDN Using Asynchronous Server Socket ?
- References:
- Re: MSDN Using Asynchronous Server Socket ?
- From: Vadym Stetsyak
- Re: MSDN Using Asynchronous Server Socket ?
- From: Zeeshan Gulzar
- Re: MSDN Using Asynchronous Server Socket ?
- From: Michael D. Ober
- Re: MSDN Using Asynchronous Server Socket ?
- Prev by Date: porting native c++ code to use with .NET
- Next by Date: Re: FileSystemWatcher advice required please
- Previous by thread: Re: MSDN Using Asynchronous Server Socket ?
- Next by thread: Re: MSDN Using Asynchronous Server Socket ?
- Index(es):
Relevant Pages
|
Loading