0

我是服务器开发的新手。我正在尝试 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

我做错了什么?

4

1 回答 1

0

如果是同一台机器,把0.0.0.0换成127.0.0.1就行了,就是本地环回接口。

于 2014-12-25T16:59:40.623 回答