I create new a project from lwip_s32k344 example and write code as bellow:
#include <lwip/sockets.h>
#define PORT 5001
#define RECV_DATA (1024)
#define SERV_IP_ADDR "192.168.31.82"
#define SERV_PORT 5001
void tcp_client(void *arg){
int sock=-1;
struct sockaddr_in Serv_addr;
char recv_data[64]={"a"};
int recv_data_len=64;
vTaskDelay(2000);
while(1){
sock=socket(AF_INET,SOCK_STREAM,0);
if(sock<0)
{
vTaskDelay(10);
continue;
}
Serv_addr.sin_family=AF_INET;
Serv_addr.sin_port=htons(SERV_PORT);
Serv_addr.sin_addr.s_addr=inet_addr(SERV_IP_ADDR);
memset(&(Serv_addr.sin_zero), 0, sizeof(Serv_addr.sin_zero));
if (connect(sock, (struct sockaddr *)&Serv_addr, sizeof(struct sockaddr)) == -1)
{
closesocket(sock);
vTaskDelay(10);
continue;
}
while(1)
{
write(sock,recv_data,recv_data_len);
vTaskDelay(10);
}
}
}
void udp_client(void *arg){
int sock=-1;
struct sockaddr_in Serve_addr;
char test_buf[]="sense_long is nb";
socklen_t addrlen=sizeof(struct sockaddr);
while(1){
sock=socket(AF_INET,SOCK_DGRAM,0);
Serve_addr.sin_family=AF_INET;
Serve_addr.sin_addr.s_addr=inet_addr("192.168.31.82");
Serve_addr.sin_port=htons(PORT);
memset(&(Serve_addr.sin_zero),0,sizeof(Serve_addr.sin_zero));
while(1){
sendto(sock,test_buf,sizeof(test_buf),0,(struct sockaddr*)&Serve_addr,addrlen);
vTaskDelay(1000);
}
}
}
I connect S32K3X4EVB-Q172 board to my computer which runs server. The udp client works but tcp client not.
Did I ignore any configuration? Thank you!