Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-29-2006, 04:12 AM   #1 (permalink)
jaro
Registered User
 
jaro's Avatar
 
Join Date: Feb 2006
Posts: 9
jaro is on a distinguished road
How do I check if the connection is still alive

Hi there,

I'm wondering is there a function out there that would tell if the socket connection is still alive(or connected).


basically I use some of this to connect to the other "station" ( don't know if these code below would help,but I just want you to know)
Code:
gethostbyname(HOST)
//..............
clientService.sin_addr=*((struct in_addr*)h->h_addr);	 	/* IP address for hostname */
clientService.sin_port = htons("4040");			/* smtp port */
clientService.sin_family = AF_INET;  			/* internet */
//................
ConnectSocket = socket(AF_INET, SOCK_STREAM, 0);
connect( ConnectSocket, (struct sockaddr*) &clientService, sizeof(struct sockaddr) )
//...................
Currently the programs works fine,it is able to retreive and process message from the other "station" (w/c acts a workspaceserver).
The problem is that when I disconnect my pc from the network (by pulling out the network cable), the program still run as if it is still connected to the other "station".

How do I check if the connection is still alive?

Regards,
Jaro
jaro is offline   Reply With Quote
Old 03-29-2006, 05:30 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
The connection, as you call it, has a 120 sec. timeout delay, so the program will run for atleast 2 minuts after pulling out the cable, befor it detects a loss in network activity.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-03-2006, 08:56 AM   #3 (permalink)
kyoryu
Registered User
 
Join Date: Apr 2003
Posts: 34
kyoryu is on a distinguished road
What are you using to check the socket for available data/receive the data?

EDIT:

Since your other thread asked about poll(), I'm going to assume you're poll()ing your sockets.

If that's the case, the way to determine if you have a disconnected socket is to see if poll() returns either POLL_READ or POLL_HUP, and a subsequent read() from the socket returns 0 bytes.

The status of POLL_HUP and POLL_READ is *not* consistent between OS's, and is somewhat undefined. What either will tell you, however, is that if you read from the socket you won't block. On an open socket, this means that there's data available.

Doing a read from that socket, once you know it won't block, and getting zero bytes then tells you that the socket is closed.
kyoryu is offline   Reply With Quote
Old 04-05-2006, 02:22 AM   #4 (permalink)
jaro
Registered User
 
jaro's Avatar
 
Join Date: Feb 2006
Posts: 9
jaro is on a distinguished road
Just found out that i can't use poll() under Windows programming.
I've started to read/work on select() and i hope that this will be the solution.
I'll post again if I encounter some problem along the way.
many thanks to those who reply to my post.
regards,
jaro
jaro is offline   Reply With Quote
Old 04-20-2006, 02:06 PM   #5 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
See "Windows Socket 2" system.
the win32 sdk help has sock2.hlp which contains all the needed info.
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with outside connection to mysql using a php page ericanca PHP 11 07-19-2005 10:33 AM
Help with outside connection to mysql using a php page ericanca Everything SQL ( MySQL, MSSQL, DB2, Postgre, Oracle, etc...) 1 04-18-2005 07:37 PM
DAO wrapper class for Connection Pooling using JNDI Mazzman Java 4 03-29-2005 07:54 AM
javascript: check if file input is undefined sde HTML, XML, Javascript, AJAX 3 03-28-2005 08:15 AM


All times are GMT -8. The time now is 06:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting