Network server won't accept connections

Feb 11, 2008 2 Replies

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


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

Dan

try

number.

shell

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required