473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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);
}
}
}
Nov 17 '05 #1
1 22649
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" <RE*************@hotmail.com> wrote in message
news:e0**************@TK2MSFTNGP14.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
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);
}
}
}

Nov 17 '05 #2

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

Similar topics

3
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...
0
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
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...
4
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,...
132
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...
1
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...
3
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...
7
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.