1

我想通过 Windows (主机)上的 C# UWP 客户端套接字与Java 服务器(在 Debian VM 来宾上)进行通信。

  • 在 Windows 上,我使用本地网络。我的地址类是 192.168.36.1。我的电脑本地 IP 是192.168.36.119. 我使用以太网接口。
  • 在 Debian Virtual(在 VMWare)上,我使用 NAT 网络配置,我的地址类是 192.168.73.1。我的电脑IP是192.168.73.129。我使用 VMware 网络适配器 VMnet8 接口。

  • 我认为StreamSocket无法脱离网络以太网接口(.36)连接到(.73)中的VMWare网络接口

  • 服务器运行良好。我也可以在 Google Chrome 上轻松访问它,并且我已经在 Windows 上使用 Telnet 对其进行了测试。

这是我的测试代码示例,我尝试连接 192.168.73.129:8082 服务器套接字。当 java 服务器在 Windows 上运行(使用我的 IP 窗口)时,它工作得很好。

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);
        }
    }
 }

如何访问 VMWare Debian 中的服务器套接字?

4

0 回答 0