Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

tcp socket connect reports fake success
Hi all,
I've written a tcp client that connects from Linux (Fedora Core 1) to
Windows
and AIX. If the connection is lost it tries to connect in 5 sec
intervals.
The problem is that when in the evening we stop the servers (tested
with
AIX, Win NT and 2000 ) and let the client running over night, in the
morning the client says it is connected.
On the client OS netstat also reports connection ESTABLISHED. And thats
when the server software is not running. On the server OS netstat says
that no such connection exists.
My code is (removed logging and other stuff) :
// if connecting didn't succeed, this function is called every 5
seconds
int connect_server()
{
struct sockaddr_in _addr;
int res;
int s;

s = socket( AF_INET, SOCK_STREAM, IPPROTO_IP );

_addr.sin_family = AF_INET;
_addr.sin_addr = gBindIp;
_addr.sin_port = 0;
if( -1 == bind( s, (struct sockaddr*)&_addr, sizeof( _addr ) )
){
close(s);
return -1;
}
_addr.sin_family = AF_INET;
_addr.sin_addr = gConnIp;
_addr.sin_port = htons(gPort);
res = connect( s, (struct sockaddr *)&_addr, sizeof(struct
sockaddr_in) );
if( -1 == res ) {
close(s);
return -1;
}

// make NONBLOCK to use the socket in select()
if( fcntl( s, F_SETFL, O_NONBLOCK | fcntl( s, F_GETFL ) ) == -1
){
close(s);
return -1;
}
return s;
}


Report this thread to moderator Post Follow-up to this message
Old Post
ten90425@gbg.bg
12-30-04 01:57 PM


Re: tcp socket connect reports fake success
ten90425@gbg.bg wrote...
> Hi all,
> I've written a tcp client that connects from Linux (Fedora Core 1) to
> Windows
> and AIX. If the connection is lost it tries to connect in 5 sec
> intervals.
> The problem is that when in the evening we stop the servers (tested
> with
> AIX, Win NT and 2000 ) and let the client running over night, in the
> morning the client says it is connected.

Put a packet sniffer on your network and see what the servers do when
they stop.  Odds are very, very good that they die silently (ie, do
not issue a RST or FIN sequence) to the clients.

Without that indication of connection loss, the client assumes "no
news is good news" regarding the connection state.

> On the client OS netstat also reports connection ESTABLISHED. And thats
> when the server software is not running. On the server OS netstat says
> that no such connection exists.
> My code is (removed logging and other stuff) :
> // if connecting didn't succeed, this function is called every 5
> seconds
> int connect_server()
> {
> struct sockaddr_in _addr;
> int res;
> int s;
>
> s = socket( AF_INET, SOCK_STREAM, IPPROTO_IP );
>
> _addr.sin_family = AF_INET;
> _addr.sin_addr = gBindIp;
> _addr.sin_port = 0;
> if( -1 == bind( s, (struct sockaddr*)&_addr, sizeof( _addr ) )
> ){
> close(s);
> return -1;
> }
> _addr.sin_family = AF_INET;
> _addr.sin_addr = gConnIp;
> _addr.sin_port = htons(gPort);
> res = connect( s, (struct sockaddr *)&_addr, sizeof(struct
> sockaddr_in) );
> if( -1 == res ) {
> close(s);
> return -1;
> }
>
> // make NONBLOCK to use the socket in select()
> if( fcntl( s, F_SETFL, O_NONBLOCK | fcntl( s, F_GETFL ) ) == -1
> ){
> close(s);
> return -1;
>         }
>        return s;
> }
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Vendor Neutral
12-31-04 01:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:39 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.