G
Guest
I am using the code of "MSDN-Using Asynchronous Server Socket"
"ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JUL.1033/cpguide/html/cpconnon-blockingserversocketexample.htm"
Here
try {
listener.Bind(localEndPoint);
listener.Listen(100);
while (true) {
// Set the event to nonsignaled state.
allDone.Reset();
// Start an asynchronous socket to listen for connections.
Console.WriteLine("Waiting for a connection...");
listener.BeginAccept( new
AsyncCallback(AcceptCallback),listener );
// Wait until a connection is made before continuing.
allDone.WaitOne();
}
Why we use
ManualResetEvent allDone = new ManualResetEvent(false);
and call allDone.Reset() every time.
and why not we use AutoResetEvent instead of ManualResetEvent. So not call
Reset method every time.
Any Reason ?.
Because when i use this code in my real application as a window service,
after some time (1 day or more) it reject to accept new sockets but service
still running. This service installed on 20 machines which is connected via
modem. But the problem occured on one or two machines.
Error : No connection could be made because the target computer actively
refused it
Code : 10061 WSAECONNREFUSED
Please help me urgently.
Zeeshan Gulzar
"ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JUL.1033/cpguide/html/cpconnon-blockingserversocketexample.htm"
Here
try {
listener.Bind(localEndPoint);
listener.Listen(100);
while (true) {
// Set the event to nonsignaled state.
allDone.Reset();
// Start an asynchronous socket to listen for connections.
Console.WriteLine("Waiting for a connection...");
listener.BeginAccept( new
AsyncCallback(AcceptCallback),listener );
// Wait until a connection is made before continuing.
allDone.WaitOne();
}
Why we use
ManualResetEvent allDone = new ManualResetEvent(false);
and call allDone.Reset() every time.
and why not we use AutoResetEvent instead of ManualResetEvent. So not call
Reset method every time.
Any Reason ?.
Because when i use this code in my real application as a window service,
after some time (1 day or more) it reject to accept new sockets but service
still running. This service installed on 20 machines which is connected via
modem. But the problem occured on one or two machines.
Error : No connection could be made because the target computer actively
refused it
Code : 10061 WSAECONNREFUSED
Please help me urgently.
Zeeshan Gulzar