SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html

Dependents:   SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more

Fork of YDwifiInterface by Takao Kishino

Revision:
52:29b4d0adddf3
Parent:
45:50d60753ade3
--- a/Socket/TCPSocketServer.cpp	Tue Mar 31 02:59:47 2015 +0000
+++ b/Socket/TCPSocketServer.cpp	Tue Mar 31 03:12:35 2015 +0000
@@ -161,21 +161,38 @@
     C_SNIC_Core *snic_core_p = C_SNIC_Core::getInstance();
     int          i;
     int          ret = -1;
+    bool         accepted = false;
     
     C_SNIC_Core::tagCONNECT_INFO_T *con_info_p;
-    for( i = 0; i < MAX_SOCKET_ID+1; i++ )
-    {
+    
+    do
+    {    
+        for( i = 0; i < MAX_SOCKET_ID+1; i++ )
+        {
         // Get connection information
-        con_info_p = snic_core_p->getConnectInfo( i );
-        if( (con_info_p->is_connected == true)
-            && (con_info_p->is_accept == true)
-            && (con_info_p->parent_socket == mSocketID) )
-        {
-            // Set socket id
-            connection.setAcceptSocket( i );
-            ret = 0;
-        }   
-    }
+            con_info_p = snic_core_p->getConnectInfo( i );
+            if( (con_info_p->is_connected == true)
+                && (con_info_p->is_accept == true)
+                && (con_info_p->parent_socket == mSocketID) )
+            {
+                // Set socket id
+                connection.setAcceptSocket( i );
+                ret = 0;
+                accepted = true;
+                break;
+            }   
+        }
+    } while( accepted == false );
+    con_info_p->is_accept = false;
+    
+    char remote_addr[ 20 ] = {'\0'};
+    sprintf( remote_addr, "%d.%d.%d.%d"
+            , (con_info_p->from_ip >> 24 ) & 0xff 
+            , (con_info_p->from_ip >> 16 ) & 0xff 
+            , (con_info_p->from_ip >> 8 )  & 0xff 
+            ,  con_info_p->from_ip         & 0xff );
+    
+    connection.set_address( remote_addr, (int)con_info_p->from_port );
     
     return ret;
 }