title: C++ Client works only with localhost C# Server
body: <p>I am working with C++ application which is windows service and C# server .
  With localhost testing everything works great, but with virtualbox system or the same network computers it doesnt work.
  I disabled windows firewall and antivirus.
  Here is my C# Server most important code:</p>
  
  <pre><code>   IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
      IPAddress ipAddress = IPAddress.Parse("192.168.1.2");
      IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 8517);
      tcpListener = new TcpListener(localEndPoint);
      tcpListener.Start();
      tcpListenerThread = new Thread(listenerSocket);
      tcpListenerThread.Start();
  }
  
  static void listenerSocket()
  {
       while (true)
       {
            try
            {
                Socket client = tcpListener.AcceptSocket();
                clientSockets.Add(client);
            }
            catch (Exception exc)
            {
                 return;
            }
        }
  }
  </code></pre>
  
  <p>And here is my C++ client most important code(according msdn examples for c++ socket clients):</p>
  
  <pre><code>connectToServer(){
      serviceState = DISCONNECTED;
      ConnectSocket = INVALID_SOCKET;
      sendbuf = "Client Service is ready";
      recvbuflen = DEFAULT_BUFLEN;
      //----------------------
      // Initialize Winsock
      iResult = WSAStartup(MAKEWORD(2,2), &amp;wsaData);
      if (iResult != NO_ERROR) {
          SaveEvent(L"WSAStartup failed");    
      }
      else{       
          SaveEvent(L"WSAStartup success");           
      }
      // Create a SOCKET for connecting to server
      ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
      if (ConnectSocket == INVALID_SOCKET) {      
          SaveEvent(L"Error creating socket for connecting to server");       
          WSACleanup();
      }
      else{       
          SaveEvent(L"Creating socket for connecting to server success");     
      }
      address.sin_family = AF_INET;
      address.sin_addr.s_addr = inet_addr( std::string(serverIP.begin(), serverIP.end()).c_str());
      address.sin_port = htons( serverPort ); 
      //----------------------
      // Connect to server.
      iResult = connect( ConnectSocket, (SOCKADDR*) &amp;address, sizeof(address) );
      if ( iResult == SOCKET_ERROR) {
          closesocket (ConnectSocket);
          serviceState = DISCONNECTED;        
          SaveEvent(L"Unable to connect to server");          
          WSACleanup();
      }
      else{
          serviceState = CONNECTED;       
          SaveEvent(L"Connected to server : " + serverIP );   
          u_long iMode = 1;
          ioctlsocket(ConnectSocket, FIONBIO, &amp;iMode);
      }
  }
  </code></pre>
  
  <p>With localhost it works and i have client and server on the same ip but with different ports.
  With different ips i got situation when server doesnt 'hear'  client.
  My log looks like this:</p>
  
  <pre><code>2017-03-31 18:01:30   Settings readed: server IP = 192.168.1.2, server port = 8517-                         
  2017-03-31 18:01:30   WSAStartup success        -                         
  2017-03-31 18:01:30   Creating socket for connecting to server success-                         
  2017-03-31 18:01:31   Unable to connect to server- 
  </code></pre>
  
  <p>I would really appreciate any kind oif help i stuck with this almost one week.
  I can that add ping to server ip works on client pc</p>