PC Review


Reply
Thread Tools Rate Thread

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

 
 
Sagaert Johan
Guest
Posts: n/a
 
      23rd Mar 2005
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);
}
}
}


 
Reply With Quote
 
 
 
 
Dale Preston
Guest
Posts: n/a
 
      24th Mar 2005
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

"Sagaert Johan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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);
> }
> }
> }
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A blocking operation was interrupted by a call to WSACancelBlockingCall -- can async I/O solve this problem? roburst network programming Ryan Liu Microsoft C# .NET 0 20th May 2008 07:02 PM
Socket Exception: A non blocking socket operation could not be completed immediately. Rollasoc Microsoft Dot NET 4 15th Sep 2006 04:49 PM
non blocking socket connect operation throw an exception =?Utf-8?B?eWFyb24=?= Microsoft C# .NET 0 21st Aug 2005 03:01 PM
GDI+ New Matrix() generates Out Of Mem Exception =?Utf-8?B?aGVyYmVydA==?= Microsoft Dot NET 1 29th Dec 2004 07:53 PM
Remoting: A blocking operation was interrupted by ..... José Joye Microsoft C# .NET 1 14th Apr 2004 02:24 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:08 PM.