473,670 Members | 2,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
WSACancelBlocki ngCall '

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

See source below.

Any Idea's ?
private void serverthrd()
{
IPAddress localAddr = IPAddress.Any;
svr = new TcpListener(loc alAddr, 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.AcceptSo cket() here.
client=null;
Console.WriteLi ne("Listen for clients...");
client = svr.AcceptTcpCl ient();
client.NoDelay= true;
client.ReceiveT imeout = 10000;
client.SendTime out = 10000;

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

// do something

// and then close
stream.Close();
client.Close();
}
catch(SocketExc eption ee)
{
Console.WriteLi ne("SocketExcep tion: {0}", ee);
}
}
}
Nov 17 '05 #1
1 22745
The WSACancelBlocki nCall 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" <RE************ *@hotmail.com> wrote in message
news:e0******** ******@TK2MSFTN GP14.phx.gbl...
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
WSACancelBlocki ngCall '

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

See source below.

Any Idea's ?
private void serverthrd()
{
IPAddress localAddr = IPAddress.Any;
svr = new TcpListener(loc alAddr, 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.AcceptSo cket() here.
client=null;
Console.WriteLi ne("Listen for clients...");
client = svr.AcceptTcpCl ient();
client.NoDelay= true;
client.ReceiveT imeout = 10000;
client.SendTime out = 10000;

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

// do something

// and then close
stream.Close();
client.Close();
}
catch(SocketExc eption ee)
{
Console.WriteLi ne("SocketExcep tion: {0}", ee);
}
}
}

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10393
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on -------------------------------------------------------------- listener = new System.Net.Sockets.TcpListener(6254); listener.Start(); //skt is a socket skt =listener.AcceptSocket(); <--- this line blocks -------------------------------------------------------------- I attempt to stop the thread...
0
1415
by: yaron | last post by:
Hi, I want to use non-blocking socket operations (and not async socket operations) When i use this code : socket.Blocking = false; socket.Connect(remote); i get this error :
20
2011
by: Charles Law | last post by:
Consider the following scenario: A data packet is sent out of a serial port and a return packet is expected a short time later. The application sending the packet needs to send another packet as soon as the return packet has been received. It needs to wait for the return packet, but time out if one is not received. Whilst packets are being exchanged the application needs to be responsive.
4
24177
by: Rollasoc | last post by:
Hi, We have a range of four products that can talk to our software (Written in C# & managed C++) via ethernet. Using standard socket class. This has all been working fine for a long time now, under DotNet 1.1. We have now converted the project to DotNet 2.0 Unfortunetely, the code no longer works for one of the products. The
132
5542
by: Zorro | last post by:
The simplicity of stack unraveling of C++ is not without defective consequences. The following article points to C++ examples showing the defects. An engineer aware of defects can avoid hard-to-find bugs. http://distributed-software.blogspot.com/2007/01/c-exception-handling-is-defective.html Regards, zorabi@ZHMicro.com http://www.zhmicro.com http://distributed-software.blogspot.com
1
2016
by: ishay44 | last post by:
I use Winsock2 (WS2_32.DLL) and i want to canceling the 'select()' blocking, in Windows Sockets 1.1 it was possible using the WSACancelBlockingCall(), but it removed for Winsock2 so how can cancel this blocking now?
3
8353
by: mp | last post by:
Code is at bottom. Basically, if I turn off socket blocking prior to connecting, I get a "Socket is not connected" error when I try to send data. However, if I do not turn off blocking, OR if I place a print statement anywhere before the send call, it works! WTF? I'd like to understand what's going on in the background here, if you know don't skimp on the details. Thanks
7
4767
by: Brendon Costa | last post by:
Hi all, I have a small python project i am working on. Basically i always have two threads. A "Read" thread that sits in a loop reading a line at a time from some input (Usually stdin) and then generating events to be processed and a "Proc" thread that processes incoming events from a queue. There will be additional threads as well that asynchronously insert events into the queue to be processed, but they are not a part of this so i...
1
20610
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but I don't see the error): "System.IO.IOException: Unable to read data from the transport connection:A blocking operation was interrupted by a call to WSACancelBlockingCall"
0
8471
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8386
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8903
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8815
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8661
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7421
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4213
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2802
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.