Network server won't accept connections

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I'm trying to make a simple network server out of an Embest SBC2410-II board
with an Ethernet port.  The code below is my server thread.  There is a main
thread that continually displays ThreadStatus, so I know that no system call is
failing.  The ThreadStatus gets to ts_CallingAccept and stays there.  When I try
to connect to this board using some proven client software, the connect() call
on my client fails, and I'm sure I'm using the right IP address and port number.
Does anyone see why this server code is not accepting connections?

    sock = socket( PF_INET, SOCK_STREAM, 0);
    if( sock == -1)
    {
        ThreadStatus = ts_SocketFailed;
        return;
    }
    int yes = 1;
    if( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1)
    {
        ThreadStatus = ts_SetsockoptFailed;
        return;
    }
    my_addr.sin_family = AF_INET;
    my_addr.sin_port = htons(MyPortNum);
    my_addr.sin_addr.s_addr = inet_addr("192.168.0.230");
    memset(my_addr.sin_zero, '', sizeof my_addr.sin_zero);
    ThreadStatus = ts_CallingBind;
    if( bind(sock, (struct sockaddr *)&my_addr, sizeof my_addr) == -1)
    {
        ThreadStatus = ts_BindFailed;
        return;
    }
    if( listen(sock, backlog) == -1)
    {
        ThreadStatus = ts_ListenFailed;
        return;
    }
    while(1)
    {
            int new_fd;
        sin_size = sizeof their_addr;
        ThreadStatus = ts_CallingAccept;
         new_fd = accept(sock, (struct sockaddr *)&their_addr, &sin_size);
         if( new_fd == -1)
         {
             ThreadStatus = ts_AcceptFailed;
             sleep(1);
         }
         else        //..we got an incoming connection on new_fd
         {
            //....Doesn't matter.  We never get here.
             close(new_fd);
         }
    }
}

 - - - - - - - - - - - - - - - - - - - - -
I know the hardware works because I can ping out from this board using the shell
command line.
Robert Scott
Ypsilanti, Michigan

Re: Network server won't accept connections

Quoted text here. Click to load it

Wireshark (was Ethereal) and tcpdump are two invaluable diagnostic tools
for trying to figure out what is happening with network connections.

Dan

Re: Network server won't accept connections
So its a TCP stream.  Try using a simple telnet client.  Also is there
any firewalls between the client and the server? (that includes
Ipchains/iptables on either side as well).  Also make sure that no
other process is hogging that port number.

Robert Scott wrote:
Quoted text here. Click to load it
try
Quoted text here. Click to load it
number.
Quoted text here. Click to load it
shell
Quoted text here. Click to load it

Site Timeline