tcp server listening, client connecting problems

Login or Register for Dates, Times and to Reply

Thread Tools Search this Thread
Top Forums Programming tcp server listening, client connecting problems
# 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:

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


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!
# 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  

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.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #830
Difficulty: Medium
JSON-RPC is a remote procedure call (RPC) protocol built on JSON, as a replacement for XML-RPC or SOAP.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

LDAP Client not connecting to LDAP server

I have very limited knowledge on LDAP configuration and have been trying fix one issue, but unsuccessful. The server, I am working on, is Solaris-10 zone. sudoers is configured on LDAP (its not on local server). I have access to login directly on server with root, but somehow sudo is not working... (9 Replies)
Discussion started by: solaris_1977
9 Replies

2. Solaris

Too much TCP retransmitted and TCP duplicate on server Oracle Solaris 10

I have problem with oracle solaris 10 running on oracle sparc T4-2 server. Os information: 5.10 Generic_150400-03 sun4v sparc sun4v Output from tcpstat.d script TCP bytes: out outRetrans in inDup inUnorder 6833763 7300 98884 0... (2 Replies)
Discussion started by: insatiable1610
2 Replies

3. Red Hat

Memory problems in NFS client server

Hi all, i have some doubts in a situation that i fail to get an answer in Google. I have a solaris 10 nfs server and 5 centos 6.0 nfs clients. The problem/situation is that in the clients the free memory is "disappearing" along the time (passing to used)..and it gets free if i umount the... (5 Replies)
Discussion started by: blast
5 Replies

4. Programming

[C++] [Unix] TCP non-blocking. Detect server disconnection procedure over, from client.

Hello! I searched forum for similar topic, with no luck, if you know one, delete this topic, and send me private message with link please. Little background: I have a lot of clients and one serwer. Client can make multiple connections on different ports and ips, but only one can be acctive... (2 Replies)
Discussion started by: ikeban
2 Replies

5. Programming

Concurrent TCP client/server

I made a program and now I need to make it concurrent. Can someone pls help me do this ? The code is this: #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <errno.h> #include <unistd.h> #include <stdio.h> #include <string.h>... (4 Replies)
Discussion started by: Johnny22
4 Replies

6. SCO

/dev/inet/tcp not listening in SCO 6.

While in SCO Openserver 5.0.7, Sybase listened to /dev/inet/tcp, the same is not working in SCO Openserver 6. The Network card is however active and pinging fine. What can be the reason? What is the way out? An early response will be appreciated. Thank you Regards TCG (2 Replies)
Discussion started by: thecobolguy
2 Replies

7. UNIX for Dummies Questions & Answers

Help connecting to linux server from shh client in windows!

I just installed the latest version of unbuntu server and want to connect from windows using a ssh client. This is my first linux server, so bare with me =) For my server... cat /etc/hostsgives me localhost ubuntuHomeI tried using ssh secure shell and putty in vista.... (11 Replies)
Discussion started by: Bandit390
11 Replies

8. Linux

NFS Server FC7 Solaris client problems!

Hi, my problem is that I am not able to grand the nfs directory on a Fedora 7 server to a standard solaris client. I always got the messages no permission. Important: No change on the client (Solaris) is possible! So I am not able to change the NFS Version on the client side to force the... (3 Replies)
Discussion started by: joerg
3 Replies

9. UNIX for Dummies Questions & Answers

TCP Listening Ports

Hello all, Can someone instruct me on how to change the listening port for ftp ( or any tcp service) from 21 to another port number? Thanks in advance.. -AJ (3 Replies)
Discussion started by: jacobsa
3 Replies

10. Shell Programming and Scripting

Perl Script Listening On A TCP Port

Hi, Im programming a perl script which will act as a daemon listening on a tcp port (2323) and will take (<stdin>) from the client (im going to use telnet) and run the arguments from (<stdin>) against an program already on the server, which is used to list books in the library at uni. So far... (1 Reply)
Discussion started by: emcb
1 Replies

Featured Tech Videos