TCP Server that handles multiple client requests at the same time using multiple threads

Dependencies:   EthernetInterface Server mbed-rtos mbed Threads

Files at this revision

API Documentation at this revision

Comitter:
lemniskata
Date:
Tue Jun 11 21:15:59 2013 +0000
Parent:
3:91fa989f29e2
Child:
5:375e278a4545
Commit message:
TCP Server that handles multiple client requests at the same time by using multiple threads

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
Server.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
--- a/EthernetInterface.lib	Tue Jun 11 20:43:40 2013 +0000
+++ b/EthernetInterface.lib	Tue Jun 11 21:15:59 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/EthernetInterface/#ec4edb780fd4
+http://mbed.org/users/lemniskata/code/EthernetInterface/#ec4edb780fd4
--- a/Server.lib	Tue Jun 11 20:43:40 2013 +0000
+++ b/Server.lib	Tue Jun 11 21:15:59 2013 +0000
@@ -1,1 +1,1 @@
-Server#a5fdd089d5c6
+http://mbed.org/users/lemniskata/code/Server/#e1db78d5ccc1
--- a/main.cpp	Tue Jun 11 20:43:40 2013 +0000
+++ b/main.cpp	Tue Jun 11 21:15:59 2013 +0000
@@ -2,80 +2,23 @@
 #include "EthernetInterface.h"
 #include "Server.h"
 
-#define SERVER_PORT   7
-#define BUFFLEN 100
-
-char buffer[256];
-
-/*void Handle_client(void const *socket_data) {
-   
-   int socket; 
-   socket = (int)socket_data;
-   int n = lwip_recv(socket ,buffer,sizeof(buffer),0); 
-
-
-   if (lwip_send(socket ,buffer,n,0)!=n) //send the content of the shared memory back to the socket 
-   {
-   
- 
-   }
-   
-
-}*/
 
 void Start_server(void const *port) {
    int _port=(int) port;
    Server my_server(_port,3);
-   my_server.Start();
+   int n=my_server.Start();
+   if(n==-1)
+   {
+        //printf("Server startup failed\n");
+   }
 }
 
-//osThreadDef(Handle_client, osPriorityNormal, DEFAULT_STACK_SIZE);
+
 osThreadDef(Start_server, osPriorityNormal, DEFAULT_STACK_SIZE);
 
 int main (void) {
   int port=7;
-   osThreadCreate(osThread(Start_server), (void *) port);
-   /*
-    EthernetInterface eth;
-    eth.init(); //Use DHCP
-    eth.connect();
-   // Thread t1(Debug, (void *) 1);
-    
-    int socket_server;
-    struct sockaddr_in localHost;
-    memset(&localHost, 0, sizeof(localHost));
-    int new_socket;
-    
-    if( (socket_server= lwip_socket(AF_INET, SOCK_STREAM, 0))<0)
-    {
-        return -1;
-    }
-    localHost.sin_family = AF_INET;
-    localHost.sin_port = htons(SERVER_PORT);
-    localHost.sin_addr.s_addr = INADDR_ANY;
-    
-    if (lwip_bind(socket_server, (const struct sockaddr *) &localHost, sizeof(localHost)) < 0) {
- 
-        return -1;
-    }
-      if (lwip_listen(socket_server,3)<0)
-  {
-    perror("listen");
-    exit(EXIT_FAILURE);
-  }
-  socklen_t newSockRemoteHostLen = sizeof(localHost);
-  int tid;
-  
-  for(tid=0;tid<=2;tid++) 
-  {
-    new_socket = lwip_accept(socket_server, (struct sockaddr*) &localHost, &newSockRemoteHostLen);
-    if (new_socket < 0)
-    {
-        return -1;
-    }
-
-       osThreadCreate(osThread(Handle_client), (void *) new_socket);
-    
-   }*/
+  osThreadCreate(osThread(Start_server), (void *) port);
+  /* do your thing*/
  
 }
\ No newline at end of file