make the mbed become a TCP client and *connect the TCP Server 192.168.1.100 * Send the data to Server and receive the data from the * server ,sending the received data through the uart
Dependencies: EthernetInterface mbed-rtos mbed
Fork of TCPEchoClient by
main.cpp
- Committer:
- shiyilei
- Date:
- 2014-10-30
- Revision:
- 7:da224eeb7f59
- Parent:
- 3:3fbf0efec25a
File content as of revision 7:da224eeb7f59:
/********************************************************* *file:TCPClient application *Creator:JacobShi *Time:2014/10/29 *Description: make the mbed become a TCP client and *connect the TCP Server 192.168.1.100 * Send the data to Server and receive the data from the * server ,sending the received data through the uart **********************************************************/ #include "mbed.h" #include "EthernetInterface.h" EthernetInterface eth; char data_buffer[150]; int main(void) { eth.init(); eth.connect(); printf("the ipaddr of the mbed is %s\n",eth.getIPAddress() ); TCPSocketConnection socket; while( socket.connect("192.168.1.100",8080)<0) { printf("connect error\n"); wait(1); } printf("the ip addr of the server is %s\n",socket.get_address() ); socket.send_all("Hello I am the client",sizeof("Hello I am the client")); while(1) { int n=socket.receive(data_buffer,150); if(n<0) break; socket.send_all("Receive OK",sizeof("Receive OK")); data_buffer[n]='\0'; printf("%s\n",data_buffer); } socket.close(); return 0; }