【发布时间】:2015-03-11 21:42:06
【问题描述】:
好的,所以基本上我使用 KryoNet 进行服务器-客户端通信,它们连接得很好,可以在测试场景中做我希望他们做的事情。但是,当我尝试从不同的网络甚至同一网络中的不同 PC 连接时,客户端似乎无法找到服务器......
服务器
static Server server;
//i dont even send on udp...
static int udpPort = 80, tcpPort = 5190;
public static void main() throws Exception {
System.out.println("Creating the server...");
server = new Server();
server.getKryo().register(SOME.class);
server.bind(new InetSocketAddress(InetAddress.getLocalHost(), tcpPort), new InetSocketAddress(InetAddress.getLocalHost(), udpPort));
server.start();
server.addListener(new ServerProgram());
还有客户
static Client client;
static int udpPort = 80, tcpPort = 5190;
public void connect(String ip) throws InterruptedException {
client = new Client();
client.getKryo().register(SOME.class);
client.addListener(this);
new Thread(client).start();
try {
client.connect(12000, ip, tcpPort, udpPort);
}
catch (IOException e) {
e.printStackTrace();
}
我注意到服务器总是在我的“本地”地址 (192.168.0.***) 上创建,所以有什么方法可以让服务器更加公开,或者我的客户必须使用类似 Hamatchi 的东西吗?
【问题讨论】:
-
本地 PC 是否有多个网络接口/IP?如果这样做,您必须明确列出要绑定到的接口/IP,而不是让 java 为您选择。如果您希望外部人员连接,绑定“仅限内部”网络将无济于事。
-
我如何绑定到特定的接口/IP(这是正确的,我在哪里可以找到所有 IP 的列表 [ipconfig /all ?])?就像我如何将我的服务器绑定到每个人都可以查找/找到以连接到服务器的外部 IP?
标签: java hosting server kryonet