Network server won't accept connections - Embedded

This is a discussion on Network server won't accept connections - Embedded ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Network server won't accept connections

  1. Network server won't accept connections

    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, '\0', 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

  2. Re: Network server won't accept connections

    On Mon, 11 Feb 2008 23:04:50 +0000, Robert Scott wrote:

    > I'm trying to make a simple network server out of an Embest SBC2410-II board
    > with an Ethernet port.


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

    Dan

  3. 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:
    > 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, '\0', 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


+ Reply to Thread