Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
Network server won't accept connections
- 02-11-2008
- Robert Scott
February 11, 2008, 11:04 pm

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

try

number.

shell

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:

try

number.

shell

Site Timeline
- » [Commercial] Training on Linux System and Kernel Programming from Professionals
- — Next thread in » Embedded Linux
-
- » Embedded Linux Workshop
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Martwa płyta PC retro - od czego zacząć?
- — The site's Newest Thread. Posted in » Electronics (Polish)
-