473,657 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect the real status of a socket?

Hi.
I am trying a csharp sample from
http://www.codeproject.com/csharp/socketsincs.asp .
(Sorry I didn't post all the source codes here, please get the codes
from above link if you want to try).
I had some troubles when I started 6 threads (each thread made a
separate connection) and sent messages to same server simultaneously.
Sometimes, not always, the socket looks like ok, but really it is
dead.
I don't why it happens.
If I can't fix this problem, I want to detect if the connection is
dead.
if( m_sock == null || !m_sock.Connect ed )
return false, that mean the client thinks it IS connected to the
server.
But after I sent the message, the server didn't receive anything.
After that, it will never work again, unless the client reconnects the
server.
I can't disconnect the connection after I sent my message, because I
want to hear the response from the server.
If the client can detect the real connection status, the client can
reconnect to the server when the connection is dead.
How do I detect the real status of a socket?

Frank
Nov 16 '05 #1
4 3841
try the Poll method
"Frank Meng" <me*******@hotm ail.com> wrote in message
news:1a******** *************** ***@posting.goo gle.com...
Hi.
I am trying a csharp sample from
http://www.codeproject.com/csharp/socketsincs.asp .
(Sorry I didn't post all the source codes here, please get the codes
from above link if you want to try).
I had some troubles when I started 6 threads (each thread made a
separate connection) and sent messages to same server simultaneously.
Sometimes, not always, the socket looks like ok, but really it is
dead.
I don't why it happens.
If I can't fix this problem, I want to detect if the connection is
dead.
if( m_sock == null || !m_sock.Connect ed )
return false, that mean the client thinks it IS connected to the
server.
But after I sent the message, the server didn't receive anything.
After that, it will never work again, unless the client reconnects the
server.
I can't disconnect the connection after I sent my message, because I
want to hear the response from the server.
If the client can detect the real connection status, the client can
reconnect to the server when the connection is dead.
How do I detect the real status of a socket?

Frank

Nov 16 '05 #2
You might also try enabling the keep alive socket option, which will add to
the amount of network traffic a socket will cause, but also tends to allow
the socket to notice that it is no longer connected a little faster than any
other method. You've discovered part of the wonders of socket programming,
which is that if something happens in the network level, it can be difficult
to determine if a socket is really still connected or not.

Ryan Gregg

"alien" <al***@sympatic o.ca> wrote in message
news:Zj******** *************@n ews20.bellgloba l.com...
try the Poll method
"Frank Meng" <me*******@hotm ail.com> wrote in message
news:1a******** *************** ***@posting.goo gle.com...
Hi.
I am trying a csharp sample from
http://www.codeproject.com/csharp/socketsincs.asp .
(Sorry I didn't post all the source codes here, please get the codes
from above link if you want to try).
I had some troubles when I started 6 threads (each thread made a
separate connection) and sent messages to same server simultaneously.
Sometimes, not always, the socket looks like ok, but really it is
dead.
I don't why it happens.
If I can't fix this problem, I want to detect if the connection is
dead.
if( m_sock == null || !m_sock.Connect ed )
return false, that mean the client thinks it IS connected to the
server.
But after I sent the message, the server didn't receive anything.
After that, it will never work again, unless the client reconnects the
server.
I can't disconnect the connection after I sent my message, because I
want to hear the response from the server.
If the client can detect the real connection status, the client can
reconnect to the server when the connection is dead.
How do I detect the real status of a socket?

Frank


Nov 16 '05 #3
"alien" <al***@sympatic o.ca> wrote in message news:<Zj******* **************@ news20.bellglob al.com>...
try the Poll method

Thank you for your message.
I added some codes, so every time I will check with Poll first before
sending data.

if(m_socket.Pol l(-1, SelectMode.Sele ctWrite))
{
LogMessage("Thi s Socket is writable.");
}
Surprisingly, it ALWAYS gives me "This Socket is writable".
Even client is in a single thread, if client keeps sending messages
(sometimes only 2 messages in a short time period) without waiting for
response, some packages will never reach the server.
The strange thing is that once I sent message A, then message B.
Message B ( the latter one) reached the server, but message A got
lost.
What is wrong?
I think that servers (like web servers) should be able to handle
thousands of accesses simultaneously.
Nov 16 '05 #4
I just found out socket is a slow method for inter process
communication.
I don't have a lot of connections, but I need to transfer several data
packages from user's process to a system service in a short period of
time from time to time.
After data was transferred, they will be processed with the system
service.
Maybe socket is not my solution.
What should I use then? MMF or named pipe?
I don't mind using Mutex etc. to slow down the process, but I don't
want to loss data.

me*******@hotma il.com (Frank Meng) wrote in message news:<1a******* *************** ****@posting.go ogle.com>...
"alien" <al***@sympatic o.ca> wrote in message news:<Zj******* **************@ news20.bellglob al.com>...
try the Poll method

Thank you for your message.
I added some codes, so every time I will check with Poll first before
sending data.

if(m_socket.Pol l(-1, SelectMode.Sele ctWrite))
{
LogMessage("Thi s Socket is writable.");
}
Surprisingly, it ALWAYS gives me "This Socket is writable".
Even client is in a single thread, if client keeps sending messages
(sometimes only 2 messages in a short time period) without waiting for
response, some packages will never reach the server.
The strange thing is that once I sent message A, then message B.
Message B ( the latter one) reached the server, but message A got
lost.
What is wrong?
I think that servers (like web servers) should be able to handle
thousands of accesses simultaneously.

Nov 16 '05 #5

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

Similar topics

9
2162
by: Brian Roberts | last post by:
I have a command line Python program that sometimes takes a bit (several minutes) to run. I want to provide an optional method for an impatient user (me!) to check the status of the program. The type and amount of status information doesn't fit nicely into a --verbose or logger -- either too little or too much information at different points. I think an optional web page would be convenient interface. The Python program would listen...
5
44984
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
1821
by: Eddy_w | last post by:
Hello, I try to ping from my mobile device with a wireless connection to my pc. I found the class clsping on the internet and it works perfect with application from pc to pc but when i use it from mobile device (win ce.net 4.2) to pc then it doesn't work anymore. I get on error on the following statement: Dim sckSocket As New System.Net.Sockets.Socket( _
3
4268
by: Szafranr | last post by:
Hi I have application where I used tcpListener to connect with another system. Every thing is ok that it's time to error handling and I have problem when the TCP client is disconect I don't know how detect this situation the same situation is when I plug out patch-cord For waiting for a data I use this loop While Me.mSocket.Connected
13
2422
by: Shailesh Humbad | last post by:
Here is an advanced PHP question. Can anyone think of a way to detect the number of bytes written to output when a script is aborted? I am sending a large file to the client, and I want to record how many bytes are actually sent. I can detect abort of the script using a shutdown handler. In the shutdown handler, I tried ob_get_length, but it returns false. I tried to read the server's log file, but it is does not contain the...
4
2803
by: Chris Johnson | last post by:
Hey all, I have a small app I have developed that periodically pings a list of server and returns their status. Given my environment I have setup the program such that a server can be down 4 minutes before I get an alert. My problem now is that is a server is rebooted, it will be back up before the 4 minute window and I will not be aware that it has rebooted. I am looking for a way (as an administrator, or not, if possible) to detect
6
2033
by: Abubakar | last post by:
Hi, lets say I have a connected SOCKET s. At some point in time, I want to know if the "s" is still valid, that it is still connected. Is there any API that I can give me this information? And can I register some callback like thing, that would inform me when "s" disconnection happens? What I usually do is while I call "send" or "recv", I get the socket_error and through that I know whats the status. But in this situation actually I...
1
4213
by: Steve | last post by:
Hi All I am using vb.net 2005 in a windows forms application I send data to the selected windows printer using a PrintDocument object Is there any way to detect if the Printer is not responding e.g turned off, out of paper etc, via code I want to display a warning if the printer needs attention rather than just
4
5499
by: The Doctor | last post by:
Hey people, I have two applications: the server, which creates a server socket, waits for a real-time signal, and if it receives one, it creates a client socket. The client, which will connect to the server. This will generate a real- time signal at the server, who will create a client socket for this client.
0
8302
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,...
1
8499
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
8601
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
7314
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...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1601
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.