I configured a TCP connection using LwIP + RTOS in microcontroller (server) connected to a PC(client program)
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, &MyIPAddr, PORT);
do
{
osDelay(5);
}
while((netconn_connect(conn, &DestIPaddr, TCP_PORT)!= ERR_OK) //wait until a PC client will be available
If a TCP client program is already running on PC , everything is ok. But if I start PC client after executing netconn_connect(..) function on microcontroller, while() condition will never be ERR_OK. How should I modify the code to correctly connect to a PC client?
You are using it wrong. If your application is a server, then the correct usage looks more-or-less like this:
Now you should use
clientNetconn
to receive/send data.listenNetconn
is used only to listen for new incoming connections and nothing more.Here's an example from the unofficial lwIP wiki - http://lwip.wikia.com/wiki/Netconn_Accept