473,468 Members | 1,369 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Socket Connected Status

2 New Member
Hi,
I have developed a C# application which sends the data to the connected client.
I am using TCP/IP protocol. The client connects with my application using 'Telnet command' through command prompt.Once the client is connected the application starts sending data to the client i.e. on the command prompt.The data is comprised of 10,000 lines and one line is sent after every 1 second to the client. The application is working pretty good. But whenever network issue arises(network deadly slows down) the application failed to send the data to the client and Telnet doesnt display "any connection to host is lost" message . what i want to do is if connection breaks up due to network problems then display a "client disconnected" message on my application. I am not succeeded yet in my task. because before i send the data i check the connection and socket.Connected still returns true even when network slows down.
How can i resolve this issue ????
please help me
Thankyou
Feb 25 '09 #1
3 7030
StevenBlake
2 New Member
is there no one eligible to answer my query...
Mar 5 '09 #2
r035198x
13,262 MVP
Have a timeout period and display the message when the timeout expires before the data has been sent?
Mar 5 '09 #3
Plater
7,872 Recognized Expert Expert
The .Connected property is only updated after a read/write, you would need to try to send data and have it fail before the .Connected property would be updated.
I have posted a simple solution in previous threads about this subject, but a user pointed out a situation in which they believe it did not work (power failure). I have not yet tested that theory.


Expand|Select|Wrap|Line Numbers
  1.         /// <summary>
  2.         /// Determines the connected state of a given socket. Note: Socket must not have data available to be read in its buffer and have no pending connections
  3.         /// </summary>
  4.         /// <param name="s">A socket with no data available to be read and no pending connections</param>
  5.         /// <returns>True on disconnected socket</returns>
  6.         public bool isDisconnected(Socket s)
  7.         {
  8.             bool part1 = s.Poll(1000, SelectMode.SelectRead);
  9.             bool part2 = (s.Available == 0);
  10.             //if (part1 & part2)//connection is closed 
  11.             return (part1 && part2); 
  12.         }
  13.  
Mar 5 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Frank Meng | last post by:
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)....
2
by: Nuno Magalhaes | last post by:
socket.Connected only gives the last access result but not the current status of the socket. What is the best way to determine if a socket is still connected? Because I want to cancel all my...
1
by: Techsol | last post by:
Hi, I have synchronous communications between a server and client. To save bandwith the connection must persist. So the socket must stay open and only be re-opened in case of communications failure....
6
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...
0
by: Arno | last post by:
Hi, I've written a class for client-socket connection, but I get a lot of times the error message "Unable to read data from the transport connection" when restart reading the stream with...
7
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...
4
by: SpreadTooThin | last post by:
client: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("192.168.1.101", 8080)) print 'Connected' s.send('ABCD') buffer = s.recv(4) print buffer s.send('exit')
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
4
by: setiarakesh | last post by:
I have designed a socket Server and developed asynchronous server . It is working fine with 60 Clients which are connecting to ths Server running at Machine (2 GB RAM and OS is Windows 2003...
4
by: keithseah | last post by:
Hi all, i've been having this problem and its kiiling me! i'm a newbie at this so i hope someone would be able to help me. picture link:...
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:
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...
0
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,...
0
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...
1
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...
0
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...
0
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.