Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

9 replies to this topic
#1
Posted 23 May 2011 - 10:09 AM
I know only one way to do that so far. Call recv function, if recv returns 0, the connection is closed, if recv returns -1, there is a problem with connection. But unfourtunatley this is not work true.
I have a multithread client program. i call recv function in an infinite loop. i check return value of recv and if its <= 0 , i do whatever i want.
So , if i close server program , recv returns -1, no problem. if i close connected socket in server by calling closesocket func , recv returns 0, still no problem. But if client's internet connection is gone for a while , example if the modem restart itself or wireless connection is broken, that time recv never returns anything.
Also if the server connection is gone, example if the modem restarted and ip changed, client's recv still doesnt return anything, just waits.
To cut a long story short, i want to know another way to check connection is alive anytime, so i will check the connection time to time. Pls another way, not recv. i dont want to set up a new connection with a new socket and port only to check, because it fails same.
Thank u for reading, im waiting for your answers.
I have a multithread client program. i call recv function in an infinite loop. i check return value of recv and if its <= 0 , i do whatever i want.
So , if i close server program , recv returns -1, no problem. if i close connected socket in server by calling closesocket func , recv returns 0, still no problem. But if client's internet connection is gone for a while , example if the modem restart itself or wireless connection is broken, that time recv never returns anything.
Also if the server connection is gone, example if the modem restarted and ip changed, client's recv still doesnt return anything, just waits.
To cut a long story short, i want to know another way to check connection is alive anytime, so i will check the connection time to time. Pls another way, not recv. i dont want to set up a new connection with a new socket and port only to check, because it fails same.
Thank u for reading, im waiting for your answers.
#2
Posted 23 May 2011 - 11:35 AM
The only way I can think of is to have some kind of mechanism between the client and the server to see if each other is still online. I don't think that there is something implemented in the TCP protocol to tell if they went offline, besides them not ACKing packets, but I could easily be wrong.
Latinamne loqueris?
#3
Posted 23 May 2011 - 01:15 PM
The only way I can think of is to have some kind of mechanism between the client and the server to see if each other is still online. I don't think that there is something implemented in the TCP protocol to tell if they went offline, besides them not ACKing packets, but I could easily be wrong.
Yes i v been thinking of it but windows doesnt allow to use raw sockets, windows xp sp2 and later. so i cannot send syn ack packets etc. is there another way?
#4
Posted 23 May 2011 - 02:23 PM
How about sending packets/messages at regular time intervals, using the already established connection, to note that the connection is still alive. If you don't hear from client in that time you can assume it's dead.
The roots of education are bitter, but the fruit is sweet.
#5
Posted 23 May 2011 - 03:09 PM
How about sending packets/messages at regular time intervals, using the already established connection, to note that the connection is still alive. If you don't hear from client in that time you can assume it's dead.
send function writes the network buffer and returns, we cannot understand if connection is broken with this, however recv returns 0 if the connection is broken but only if broken normal ways , for example if someon cut the ethernet cable, recv function never returns, so we cannot know if the connection is alive or not.
i can try to connect at spesific time intervals but i dont want to do that because i use already 2 socket and port , one of them for file transfer and one of them for normal comunication. i will do that if the last chance...
#6
Posted 23 May 2011 - 04:31 PM
If you are using a multithreaded client, then you CAN know. Just have the calling thread monitor the child threads to see how long it takes for a reply.
Latinamne loqueris?
#7
Posted 23 May 2011 - 06:17 PM
If you are using a multithreaded client, then you CAN know. Just have the calling thread monitor the child threads to see how long it takes for a reply.
Actually i use select() function for multiclient, i use threads for other jobs. I solved the problem with the bad way , with a new socket and port. server always listens, if any client try to connect, accept it and close connection back. So clients try to connect every 10 second to server, after connection is ok, clients also close connection, i mean they only try to connect, no comunication, if they are able to connect, connection is alive, if not, restart itself..
#8
Posted 24 May 2011 - 05:47 AM
You could use the Windows API asynchronous file functions to write and read from the socket. That way you can time it.
Latinamne loqueris?
#9
Posted 24 May 2011 - 08:11 AM
You could use the Windows API asynchronous file functions to write and read from the socket. That way you can time it.
Yes but i need to change my programming style totally to do that, honestly i have no experience about asynchronous communication. Thank for advice, thank also to other replies.
#10
Posted 19 June 2011 - 10:24 PM
Try to ping the servers .
Send ping and wait for pong
Send ping and wait for pong
Also tagged with one or more of these keywords: connection
Language Forums →
Databases →
unable to read data from the transport connection an existing connection was forcibly closed by the remote host in postgresql...Started by viveq, 22 Aug 2013 ![]() |
|
![]() |
||
Language Forums →
PHP →
PHP Remote Server Database Connection ErrorStarted by KodeKool, 01 Mar 2013 ![]() |
|
![]() |
||
Language Forums →
Java →
NetBeans and Data Base connectionStarted by Petros, 16 Feb 2013 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
ASP, ASP.NET and Coldfusion →
asp.net in my pc without internet connectionStarted by apysan, 28 Jan 2013 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Terminal and remote connectionsStarted by MaxBummer, 15 Jan 2013 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download