The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Remotely connecting to HP-UX poses a lot of problems rookie8278 HP-UX 3 05-29-2008 02:51 PM
NFS Server FC7 Solaris client problems! joerg Linux 3 07-12-2007 02:34 PM
how to find port numbers a web server is listening to laddu IP Networking 6 02-16-2007 06:40 AM
Problems connecting Solaris 10 to network via ISP christian_hicks SUN Solaris 7 12-24-2004 12:58 PM
VNC Server http listening port kxchen_home Linux 6 02-06-2004 09:23 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-18-2008
Registered User
 

Join Date: Mar 2008
Posts: 3
tcp server listening, client connecting problems

hello everyone. I tried searching for something related to this, but I figured it was time to ask my own question. I am experiencing these problems using Ubuntu 7.04

I am starting up a TCP listener/server and once connected, will act as a communication/control link with a program on another computer. In the final iteration I want it to run it like a daemon, disconnected from a controlling process so I am going to do:

Code:
result = fork()
if (result == 0){
    //close stdio handles and reopen to /dev/null
    setsig()
    umask(0)

    socket()
    bind()
    listen()
    accept()
}
else
    _exit(0)
This is simplified as i am using functions and setting socket options, particularily the SO_REUSEADDR option.

If I do NOT run the fork and just run the socket->bind->listen->accept I get the same problems.

The problem is:

The client connecting, whether it is my client, or even netcat will connect properly, but then the server immediately sends a disconnect. The server does not get out of accept() during this, and even stranger it is random, and sometimes it works (60%), and sometimes it doesn't (40%).

I could tell it connected and disconnected right away by using wireshark, I got a SYN -> SYN/ACK -> ACK and then right away FIN/ACK -> FIN/ACK -> FIN. Using netstat -ta also shows the ports getting gummed up in TIME_WAIT as though it did connect and disconnect.

What i think could be the problem

Two things I have done:

one is to not set the SO_REUSEADDR parameter, and it then works as expected, although I have not done as much testing because it requires you to wait for a minute after each test for the TIME_WAIT to clean up.

two, before I set up the socket, I read some parameters from a config file, by opening and closing it. If I comment this out and hard-code the port to listen on, etc, the occurance of it is MUCH less, although can still happen.



I am at my wits end with this. Is there anything I can do to figure this out or help debug it. I am pretty sure it has to do with file handles getting gummed up or something like that. But i have no Idea!

Thanks for reading!
Reply With Quote
Forum Sponsor
  #2  
Old 03-18-2008
Registered User
 

Join Date: Feb 2005
Posts: 53
Dont you need a loop with read() after accept()?
Reply With Quote
  #3  
Old 03-19-2008
Registered User
 

Join Date: Mar 2008
Posts: 3
Sorry. You are right. After a successful accept() I go into a while loop where I read and do various things. I just wrote slimmed down code to give an over-view of what I was doing. I am doing all the error checking and never return a -1. The program, when a proper connection does happen, works perfectly, however, the chances of getting an accept is about 50/50, BUT the client DOES briefly connect.
Reply With Quote
  #4  
Old 03-19-2008
Registered User
 

Join Date: Feb 2005
Posts: 53
Hi,

My suggestion: check for ECONREFUSED error in client.
I think the old connections can affect newly relaunched server
and maybe they overflow listen specified queue length.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux, ubuntu

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:50 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0