2020-06-08 02:15 AM
Snuippet of source code
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART3_UART_Init();
Print("USART init ok\n");
MX_USB_OTG_FS_PCD_Init();
Print("USB pcd init ok\n");
MX_LWIP_Init();
Print("LWIP init ok\n");
/* USER CODE BEGIN 2 --------------------------------------------------------------------------------------------------------------------------------*/
struct tcp_pcb * tcp_client = {0};
tcp_client = tcp_new();
if(tcp_client != 0)
{
Print("tcp_new ok\n");
err_t error = {0};
error = tcp_bind(tcp_client, IP_ADDR_ANY);
if(error == ERR_OK)
{
Print("tcp_bind ok\n");
err_t errorConnect = {0};
struct ip4_addr remoteIP;
IP4_ADDR(&remoteIP, 192, 168, 127, 250);
errorConnect = tcp_connect(tcp_client, &remoteIP, 4002, tcpConnect);
if(errorConnect == ERR_OK)
{
Print("tcp_connect ok\n");
}
else
{
Print("Error: tcp_connect \n");
}
}
else
{
Print("Error: tcp_bind\n");
}
}
else
{
Print("Error: tcp_new faild\n");
}