There are 2 messages in this thread.
You are currently looking at messages 0 to 2.
Hi, I am really looking for some help in how to write code for my FPGA boardfor implementing a TCP Client using lwIP API using the commands likenetconn_connect() and so on. I found some documentation on how to build aTCP server but I could not find any help for TCP client. Any help regardingon how to build a client would be great. If any body has an idea regardingone of teh three topics which i have mentioned below, then that would behelping me a lot: 1)I am looking for some basic explanation like what are the steps i need toconsider to write a client code from scratch. 2)or a sample code which shows the basic implementation of TCP client usinglwIP API 3)or what changes should I need to make in the server program so that itcan 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