static void tcp_client_thread(void *arg)
{
int clientSocket;
struct sockaddr_in serverAddr;
char sendbuf[200];
char recvbuf[200];
int iDataNum;
if((clientSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
// perror("socket");
// return 1;
}
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(CLIENT_PORT);
serverAddr.sin_addr.s_addr = inet_addr(INADDR);
if(connect(clientSocket, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0)
{
rt_kprintf("connect");
// return 1;
}
rt_kprintf("connect with destination host...
");
while(1)
{
send(clientSocket, sendbuf, strlen(sendbuf), 0);
if(strcmp(sendbuf, "quit") == 0)
break;
iDataNum = recv(clientSocket, recvbuf, 200, 0);
recvbuf[iDataNum] = ' ';
rt_kprintf("recv data of my world is: %s
", recvbuf);
}
lwip_close(clientSocket);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>