Altera_Forum
Honored Contributor
16 years agoNicheStack Client doesn't Connect
Hi,
First of all I'm fairly new to sockets programming. I've got 2 NIOS's running on 2 boards - a SII and a SIII dev board. On the SII I have a server running, listening on a specified port. This server works fine as I can connect to it using software on a PC. On the SIII, I am trying to write a client that connects to this server on the SII. The SIII runs uCOS/II with NicheStack. On the SIII, what I do is 1) create the socket using "socket()" 2) setup server IP and PORT 3) connect 4) cleanup (socket close etc) Here's a snip of my code:int clientSocket;
struct sockaddr_in addr;
socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
addr.sin_port = htons(PORT); // port that the server listens on
IP4_ADDR(addr.sin_addr.s_addr, IP0,IP1,IP2,IP3); // server IP used here
if (connect(clientSocket, (struct sockaddr*)&addr, sizeof(addr)) < 0)
printf("connect failed");
else {
// do the stuff I want to do, like send() etc
}
socketclose(clientSocket);On the UART output (stdout,stderr) of the SII I can see the connection was accepted on port 'x'. 'x' is not the same as the port value I specified the server port to be, but AFAIK this is the client port that gets 'chosen' by the stack. The SIII NicheStack doesn't recognise this accept and retries 4 times to connect, and finally gives up with a "-1" return value from the "connect()" call. On the SII UART output I see 4 "accepted connection from...." messages. Can one of you guru's please check my sequence of events/calls. Did I miss something? As I said, I'm able to connect and get comms through to the specific server running on the SII, but when trying to do the same from the SIII, NicheStack doesn't realise that the connection was indeed accepted and retries. Thanks