物联网lwIP网络开发 4.3TCP Client实现

TCP Client实现

C/S模型

物联网lwIP网络开发 4.3TCP Client实现_第1张图片

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vadgEoXl-1613904146552)(04-TCP Client端实现.assets/image-20191204191911070.png)]

Client 端功能分析

PC_S STM32_C acbdefghijklmn 小写转大写 ABCDEFGHIJKLMN PC_S STM32_C
void vTcpClientTask(void)
{

	int 	 cfd, n, i;
	struct sockaddr_in server_addr;
	
	//创建socket
	cfd = socket(AF_INET, SOCK_STREAM, 0);
	
	server_addr.sin_family 			= AF_INET;
	server_addr.sin_port   			= htons(SERVER_PORT);
	server_addr.sin_addr.s_addr = inet_addr(SERVER_IP);
	//连接到服务器
	connect(cfd, (struct sockaddr*)&server_addr, sizeof(server_addr));
	printf("server is connect ok\r\n");
	
	while(1){
		//等待服务器发送数据
		n = read(cfd, ReadBuff, BUFF_SIZE);
		//进行大小写转换
		for(i = 0; i < n; i++){
		
			ReadBuff[i] = toupper(ReadBuff[i]);		
		}
		//写回服务器
		write(cfd, ReadBuff, n);
	}
}


你可能感兴趣的:(lwIP网络,网络,stm32)