make the mbed become a server * and receive the data from the client * send the data to the screen. * confirm the server ip is 192.168.1.101

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of TCPEchoServer by mbed official

Files at this revision

API Documentation at this revision

Comitter:
shiyilei
Date:
Thu Oct 30 16:55:14 2014 +0000
Parent:
6:5dae237341f7
Commit message:
make the mbed become a server; * and receive the data from the client; * send the data to the screen.; * confirm the server ip is 192.168.1.101

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 5dae237341f7 -r 93f5f670deb9 EthernetInterface.lib
--- a/EthernetInterface.lib	Tue Jun 04 16:07:06 2013 +0100
+++ b/EthernetInterface.lib	Thu Oct 30 16:55:14 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
diff -r 5dae237341f7 -r 93f5f670deb9 main.cpp
--- a/main.cpp	Tue Jun 04 16:07:06 2013 +0100
+++ b/main.cpp	Thu Oct 30 16:55:14 2014 +0000
@@ -1,34 +1,43 @@
+/**************************************
+*file :TcpServer test
+*Creator:JacobShi
+*Time:2014/10/29
+* Description:make the mbed become a server
+* and receive the data from the client
+* send the data to the screen.
+* confirm the server ip is 192.168.1.101
+***************************************/
 #include "mbed.h"
 #include "EthernetInterface.h"
-
-#define ECHO_SERVER_PORT   7
-
-int main (void) {
-    EthernetInterface eth;
-    eth.init(); //Use DHCP
+EthernetInterface eth;
+#define  PORT  8080
+char databuffer[100];
+int main(void)
+{
+    eth.init("192.168.1.101","225.225.225.0","192.168.1.1");
     eth.connect();
-    printf("IP Address is %s\n", eth.getIPAddress());
+    printf("the ip address of the mbed is :%s\n",eth.getIPAddress());
     
     TCPSocketServer server;
-    server.bind(ECHO_SERVER_PORT);
+    TCPSocketConnection client;
+    server.bind(PORT);
     server.listen();
+    server.accept(client);
+    client.set_blocking(true,NULL);
+    printf("the ip addr of the client is :%s\n",client.get_address() );
     
-    while (true) {
-        printf("\nWait for new connection...\n");
-        TCPSocketConnection client;
-        server.accept(client);
-        client.set_blocking(false, 1500); // Timeout after (1.5)s
-        
-        printf("Connection from: %s\n", client.get_address());
-        char buffer[256];
-        while (true) {
-            int n = client.receive(buffer, sizeof(buffer));
-            if (n <= 0) break;
-            
-            client.send_all(buffer, n);
-            if (n <= 0) break;
-        }
-        
-        client.close();
+    while(1)
+    {
+       int n=client.receive(databuffer,sizeof(databuffer));
+       if(n<=0)
+        break;
+        client.send_all("receive OK",sizeof("receive OK"));
+       printf("the receive data is :\n");
+             for(int i=0;i<n;i++)
+             {
+                printf("%c\n",databuffer[i]);
+            }
+
     }
+    client.close();
 }
diff -r 5dae237341f7 -r 93f5f670deb9 mbed-rtos.lib
--- a/mbed-rtos.lib	Tue Jun 04 16:07:06 2013 +0100
+++ b/mbed-rtos.lib	Thu Oct 30 16:55:14 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed-rtos/#1be1070d822f
diff -r 5dae237341f7 -r 93f5f670deb9 mbed.bld
--- a/mbed.bld	Tue Jun 04 16:07:06 2013 +0100
+++ b/mbed.bld	Thu Oct 30 16:55:14 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file