Kryonet connect udp:无法分配请求的地址

时间:2014-12-24 16:51:59

标签: udp client port server kryonet

我是服务器开发的新手。我正在尝试Kryonent。我使用

创建了一个服务器
server.bind(8000,30003)//8000 as tcp port, 30003 as udp port

和使用

的客户
client.connect(5000,"0.0.0.0",8000,30003);//5000 is timeout

我使用IP 0.0.0.0在同一台Windows笔记本电脑上测试客户端和服务器。 发生例外:

java.io.IOException: Unable to connect to: /0.0.0.0:30003
at com.esotericsoftware.kryonet.UdpConnection.connect(UdpConnection.java:66)
at com.esotericsoftware.kryonet.Client.connect(Client.java:171)
at com.esotericsoftware.kryonet.Client.connect(Client.java:110)
at chen.yiou.kryonetApp.KRClient.initClient(KRClient.java:31)
at chen.yiou.kryonetApp.KRClient.<init>(KRClient.java:20)
at chen.yiou.kryonetApp.KRClient.main(KRClient.java:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Caused by: java.net.BindException: Cannot assign requested address: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Net.java:435)
at sun.nio.ch.DatagramChannelImpl.connect(DatagramChannelImpl.java:738)
at sun.nio.ch.DatagramSocketAdaptor.connectInternal(DatagramSocketAdaptor.java:81)
at sun.nio.ch.DatagramSocketAdaptor.connect(DatagramSocketAdaptor.java:108)
at com.esotericsoftware.kryonet.UdpConnection.connect(UdpConnection.java:56)
... 10 more

我做错了什么?

1 个答案:

答案 0 :(得分:0)

如果它是同一台机器,只需将0.0.0.0替换为127.0.0.1,即本地环回接口。