}
}while(ret!=0);
printf("ESP8266TCPservertask>listenok\n”);
Wait until the TCP client is connected to the server; then start receiving data packets
when the TCP communication is established:
int32client_sock;
int32len=sizeof(structsockaddr_in);
for(;;){
printf("ESP8266TCPservertask>waitclient\n”);
/*blockherewaitingremoteconnectrequest*/
if((client_sock=accept(listenfd,(structsockaddr*)&remote_addr,(socklen_t
*)&len))<0){
printf("ESP8266TCPservertask>acceptfail\n");
continue;
}
printf("ESP8266TCPservertask>Clientfrom%s%d\n",
inet_ntoa(remote_addr.sin_addr),htons(remote_addr.sin_port));
char*recv_buf=(char*)zalloc(128);
while((recbytes=read(client_sock,recv_buf,128))>0){
recv_buf[recbytes]=0;
printf("ESP8266TCPservertask>readdatasuccess%d!\nESP8266TCPservertask
>%s\n",recbytes,recv_buf);
}
free(recv_buf);
if(recbytes<=0){
printf("ESP8266TCPservertask>readdatafail!\n");
close(client_sock);
}
}
2. Compile the application program, generate firmware and download it into the ESP8266
module.
3. Power off the module, and change it to operation mode; then power on the module and
run the program.
4. Establish a TCP client using the network debugging tool, then connect the TCP client
with the ESP8266 TCP server, and start sending data.