即使我传递了随机有效的IP地址,下面的函数也始终返回NetworkError.Ok错误状态。为什么会这样?
public NetworkError Init(string ip, int port)
{
NetworkTransport.Init();
ConnectionConfig config = new ConnectionConfig();
channelId = config.AddChannel(QosType.AllCostDelivery);
HostTopology topology = new HostTopology(config, 1);
hostId = NetworkTransport.AddHost(topology, 0);
NetworkTransport.Connect(hostId, ip, port, 0, out error);
return (NetworkError)error;
}
我创建了具有其他功能的服务器(如下),我想检查是否真的连接了我制作的服务器。我该如何实现?
public void Init(int port)
{
NetworkTransport.Init();
ConnectionConfig config = new ConnectionConfig();
channelId = config.AddChannel(QosType.AllCostDelivery);
HostTopology topology = new HostTopology(config, 1);
hostId = NetworkTransport.AddHost(topology, port, null);
}
注意:我正在与Android智能手机热点(在其上运行服务器)连接的笔记本电脑(客户端)上调试。