TCP Client using lwIP API

M

micro

Guest
Hi,
I am really looking for some help in how to write code for my FPGA boar
for implementing a TCP Client using lwIP API using the commands lik
netconn_connect() and so on. I found some documentation on how to build
TCP server but I could not find any help for TCP client. Any help regardin
on how to build a client would be great. If any body has an idea regardin
one of teh three topics which i have mentioned below, then that would b
helping me a lot:

1)I am looking for some basic explanation like what are the steps i need t
consider to write a client code from scratch.

2)or a sample code which shows the basic implementation of TCP client usin
lwIP API

3)or what changes should I need to make in the server program so that i
can run as a client

Kind Regards,
Mahee



---------------------------------------
Posted through http://www.FPGARelated.com
 
The easiest way I found for that, is to use the socket API.

The CONNECT code looks similar to this:

struct sockaddr_in sServer;
sServer.sin_len = sizeof(struct sockaddr_in);
sServer.sin_family = AF_INET;
sServer.sin_port = MY_PORT_NUMBER;
inet_aton("123.45.123.45", &(sServer.sin_addr));
memset(&(sServer.sin_zero), 0, sizeof(sServer.sin_zero));

int nSocket = lwip_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (nSocket < 0) {
printf("lwip_socket() returned -%d\r\n", -nSocket);
return;
}

printf("Connecting to server\r\n");

int nErr = lwip_connect(nSocket, (struct sockaddr*)(&sServer),
sizeof(sServer));
if (nErr < 0) {
printf("lwip_connect() returned -%d, errno=%d\r\n", -nErr,
lwip_get_err(nSocket));
return;
}

After that, you can use lwip_send() and lwip_recv() for data
transmission.

Best regards
 

Welcome to EDABoard.com

Sponsor

Back
Top