Sponsored Content
Top Forums Programming tcp server listening, client connecting problems Post 302176612 by pjwhite on Tuesday 18th of March 2008 06:27:57 PM
Old 03-18-2008
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!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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 127.0.0.1 localhost 127.0.1.1 ubuntuHomeI tried using ssh secure shell and putty in vista.... (11 Replies)
Discussion started by: Bandit390
11 Replies

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
GETPEEREID(3)						   BSD Library Functions Manual 					     GETPEEREID(3)

NAME
getpeereid -- get the effective credentials of a UNIX-domain peer LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/types.h> #include <unistd.h> int getpeereid(int s, uid_t *euid, gid_t *egid); DESCRIPTION
The getpeereid() function returns the effective user and group IDs of the peer connected to a UNIX-domain socket. The argument s must be a UNIX-domain socket (unix(4)) of type SOCK_STREAM on which either connect(2) has been called, or one returned from accept(2) after bind(2) and listen(2) have been called. If non-NULL, the effective used ID is placed in euid, and the effective group ID in egid. The credentials returned to the accept(2) caller are those of its peer at the time it called connect(2); the credentials returned to the connect(2) caller are those of its peer at the time it called bind(2). This mechanism is reliable; there is no way for either side to influ- ence the credentials returned to its peer except by calling the appropriate system call (i.e., either connect(2) or bind(2)) under different effective credentials. One common use of this routine is for a UNIX-domain server to verify the credentials of its client. Likewise, the client can verify the cre- dentials of the server. IMPLEMENTATION NOTES
On NetBSD, getpeereid() is implemented in terms of the LOCAL_PEEREID unix(4) socket option. RETURN VALUES
The getpeereid() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indi- cate the error. ERRORS
The getpeereid() function fails if: [EBADF] The argument s is not a valid descriptor. [ENOTSOCK] The argument s is a file, not a socket. [ENOTCONN] The argument s does not refer to a socket on which connect(2) have been called nor one returned from listen(2). [EINVAL] The argument s does not refer to a socket of type SOCK_STREAM, or the kernel returned invalid data. SEE ALSO
connect(2), getpeername(2), getsockname(2), getsockopt(2), listen(2), unix(4) HISTORY
The getpeereid() function appeared in NetBSD 5.0. BSD
August 8, 2007 BSD
All times are GMT -4. The time now is 08:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy