473,769 Members | 2,245 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket.Poll - SelectRead vs. SelectError

I have a process which accepts multiple asynchronous TCP socket connections.
Periodically I want this task to check for abnormal disconnection by each
client. The code that detects this correctly is:

if (( socket.Poll( 1, SelectMode.Read )) &&
( socket.Availabl e == 0 ))
{
// abnormal disconnect
}

but this periodically seems to detect a failure when the socket is still
working correctly (perhaps the wait period
of 1 is too short?)

also, the documentation infers this should work:

if ( socket.Poll( 1, SelectMode.Erro r ))
{
// error
}

Q1: What's the deal with SelectMode.Erro r - why does it not detect an error?
Is abnormally disconnected not an error?

Q2: What happens when the interval specified (i.e. 1 in the first example)
elapses without getting a result; does this generate an exception or return
an error?

Q3: Is there a foolproof way of detecting that a socket is no longer going
to work?

TIA
Chris Hough
Nov 16 '05 #1
0 2070

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

Similar topics

2
271
by: Helmut Gardner | last post by:
Hi folks is it possible to let VB.NET call a specific handler, when a socket gets closed (either as a server, or as a client) Thank Helmut
3
4638
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
5
45052
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; while(tcpSocket.Connected)
0
4522
by: soaphead | last post by:
Can I use Socket.Poll for blocking socket? It is unclear in documentation if I can use this with a synchronous socket, can my code possibly turn a synchronous socket to asynchronous? It seems to work but I have some problems with outside.Receive, it gives me a SocketException "An existing connection was forcibly closed by the remote host" at random times, also outside.Poll will say it has data but outside.Receive returns with nothing...
2
702
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
0
991
by: Sektor | last post by:
Hi guys, I have just a problem with the Select timeout parameter. The MSDN tells us: microSeconds The time-out value, in microseconds. A -1 value indicates an infinite time-out. I try to use -1 as timeout value but the select returns immediately. That's correct if, at least, one of the list passed to the select has count property 0.
7
16943
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to write an helper method that will tell if the socket is connected or not , but it's not working good continue to tell me that the socket is connectedeven if the other party already call shutdown(both) + close , or , even if the other party close the...
3
3105
by: JDavis | last post by:
I have created a static class-level socket for use by the class member functions: static Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); The Connect and Disconnect methods work fine, as does the synchronous Send method. However, the Poll method returns true for SelectMode.SelectWrite and false for SelectMode.SelectRead. Therefore, synchronous Read won't return anything.
21
5671
by: puzzlecracker | last post by:
Problem: I send a lot of requests to the application (running on a different box, of course), and I receive back responses from the app . Below: socket corresponds to Socket socket=new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
0
10215
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
10049
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...
1
9996
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8872
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
5307
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...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
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
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.