AcceptTcpClient() generates a exception A blocking operation was interrupted by a call to WSACancelB

S

Sagaert Johan

Hi
Ii have a simple server thread in an app that listens for connections, for
some unclear reason an exception is thrown
every now and then : 'A blocking operation was interrupted by a call to
WSACancelBlockingCall '

Any suggestion why this may happen ?
The Exception is thrown by the svr.AcceptTcpClient() method

See source below.

Any Idea's ?


private void serverthrd()
{
IPAddress localAddr = IPAddress.Any;
svr = new TcpListener(localAddr, 2028);
TcpClient client=null;

svr.Start();
while(true)
{
try
{
// Enter the listening loop.

// Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
client=null;
Console.WriteLine("Listen for clients...");
client = svr.AcceptTcpClient();
client.NoDelay=true;
client.ReceiveTimeout = 10000;
client.SendTimeout = 10000;

// Get a stream object for reading and writing
NetworkStream stream = client.GetStream();

// do something

// and then close
stream.Close();
client.Close();
}
catch(SocketException ee)
{
Console.WriteLine("SocketException: {0}", ee);
}
}
}
 
D

Dale Preston

The WSACancelBlockinCall exception generally happens when you stop
listening. Listen is a blocking method. When you stop it by closing the
socket or for other reasons, that is the error you get. The following
seems, though, to be your problem and is quoted from the MSDN library
description for ReceiveTimeout:

The ReceiveTimeout property determines the amount of time that the Read
method will block until it is able to receive data. This time is measured in
milliseconds. If the time-out expires before Read successfully completes,
TcpClient will throw a SocketException. There is no time-out by default.

HTH

Dale Preston
MCAD, MCDBA, MCSE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top