473,396 Members | 1,840 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,396 software developers and data experts.

Socket Connected Status

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 7014
is there no one eligible to answer my query...
Mar 5 '09 #2
r035198x
13,262 8TB
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 Expert 4TB
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:...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.