我想与Windows上的 C#UWP客户端套接字(主机)通信到 Java服务器(在Debian VM guest虚拟机上)。
192.168.36.119
。我使用以太网接口。在Debian Virtual(在VMWare上)上,我使用NAT网络配置,我的地址类是192.168.73.1。我的计算机IP为192.168.73.129
。我使用VMware Network Adapter 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中访问服务器套接字?