Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
20 years ago

TCP connection example

I made this post earlier under the microC-subject, however, I would also be interesting in a general standalone example using lwIP.

I am trying to make a TCP connection to a server with a nios II dev board. Does anyone have an example code on how that is done. I have tried with the following code with failing results, I think it has something to do with the destination IP.

The destination address is 192.168.1.2 which is set below.

conn_sock = socket(AF_INET, SOCK_STREAM, 0);

addr2.sin_family = AF_INET;

addr2.sin_port = htons(5824);

addr2.sin_addr.s_addr = inet_addr("192.168.1.2");

connect(conn_sock, (struct sockaddr *)&addr2, sizeof(struct sockaddr_in));

send(conn_sock, buf, strlen(buf), 0);

close(conn_sock);

Cheers. /E

3 Replies