![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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)
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! |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Dont you need a loop with read() after accept()?
|
|
#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.
|
|
#4
|
|||
|
|||
|
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. |
|||
| Google The UNIX and Linux Forums |