1

I would like communicate with a C# UWP Client socket on Windows (host) to a Java server (on Debian VM guest).

  • On windows, I use local network. My adress class is 192.168.36.1. My computer local IP is 192.168.36.119. I use Ethernet Interface.
  • On Debian Virtual (on VMWare), I use NAT network configuration, my adress class is 192.168.73.1. My computer IP is 192.168.73.129. I use VMware Network Adapter VMnet8 interface.

  • I think the StreamSocket can not get out of the network ethernet interface (.36) to connect to the VMWare network interface in (.73)

  • The server work well. I can also reach it on Google Chrome easyly and I have tested it with Telnet on Windows.

Here is my test code sample, I try to connect on 192.168.73.129:8082 server socket. It Work very well when java server running on Windows (with my IP windows).

private async void StartClient()
    {
        try
        {
            string result = string.Empty;

            // Create the StreamSocket and establish a connection to the echo server.
            using (var streamSocket = new Windows.Networking.Sockets.StreamSocket())
            {
                // The server hostname that we will be establishing a connection to. In this example, the server and client are in the same process.
                var hostName = new Windows.Networking.HostName("192.168.73.129");

                this.clientListBox.Items.Add("client is trying to connect...");

                //await streamSocket.ConnectAsync(endPointPair);
                await streamSocket.ConnectAsync(hostName, PortNumber);

                this.clientListBox.Items.Add("client connected");

                // Send a request to the echo server.
                string request = "Hello, World!";
                using (Stream outputStream = streamSocket.OutputStream.AsStreamForWrite())
                {
                    using (var streamWriter = new StreamWriter(outputStream))
                    {
                        await streamWriter.WriteLineAsync(request);
                        await streamWriter.FlushAsync();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult);
            this.clientListBox.Items.Add(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message);
        }
    }
 }

How I can reach the server socket in VMWare Debian ?

DevLoots
  • 747
  • 1
  • 6
  • 21
  • Start by using from cmd.exe >Ping 192.163.73.129 to see if you can connect to server. Then try the same using the computer name instead of the IP address. Is the server listening to port 8082 or a different port number? You can see the list of connection using from cmd.exe >Netstat -a Try connecting using a browser and check if you see the connection with Netstat -a. – jdweng Aug 29 '18 at 09:50
  • The server work well. Ping is ok, I can also reach it on Google Chrome easyly and I have tested it with Telnet on Windows to VM. It's ok too. It's just UWP socket cannot reach it. I think that UWP StreamSocket cannot reach another network interface card. – DevLoots Aug 29 '18 at 10:13
  • If you can ping using the same host name as in the code then you have a route. The issue is then the port number. Are you sure the port number 8082 is correct and that it is not being blocked? – jdweng Aug 29 '18 at 10:43
  • Yes 8082 is correct and I have try with other port number. On windows, when I use the command : `telnet 192.168.73.129 8082`, I can see a new app detected on virtual machine server – DevLoots Aug 29 '18 at 10:51
  • Try changing following so you are not connecting Async. It is possible you are trying to read data before the connection is completing : await streamSocket.ConnectAsync(hostName, PortNumber); – jdweng Aug 29 '18 at 11:08
  • I do not understand, should I try other ports or change the ConnectAsync method? I try with 8080,8081,8082 it's the same problem. – DevLoots Aug 29 '18 at 12:18
  • As I said using Async connect you may not actually be connect when you try to read. I asked about the port number before you said it was working with Telnet. I suspect that the CR being used is wrong that is causing the issue. Check the Telnett settings to see what return is being used. – jdweng Aug 29 '18 at 12:32

0 Answers0