我是 android 新手,我正在尝试创建一个服务器套接字。代码如下。
我不断收到警告。可以修吗?我可以忽略它吗?
03-28 15:47:34.460: W/System.err(3185): java.net.BindException: bind failed: EADDRINUSE (Address already in use)
03-28 15:47:34.460: W/System.err(3185): at libcore.io.IoBridge.bind(IoBridge.java:89)
03-28 15:47:34.460: W/System.err(3185): at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:150)
03-28 15:47:34.460: W/System.err(3185): at java.net.ServerSocket.<init>(ServerSocket.java:100)
03-28 15:47:34.470: W/System.err(3185): at java.net.ServerSocket.<init>(ServerSocket.java:69)
03-28 15:47:34.470: W/System.err(3185): at <path>$server.run(<filename>.java:302)
03-28 15:47:34.470: W/System.err(3185): at java.lang.Thread.run(Thread.java:856)
03-28 15:47:34.470: W/System.err(3185): Caused by: libcore.io.ErrnoException: bind failed: EADDRINUSE (Address already in use)
03-28 15:47:34.470: W/System.err(3185): at libcore.io.Posix.bind(Native Method)
03-28 15:47:34.470: W/System.err(3185): at ibcore.io.ForwardingOs.bind(ForwardingOs.java:39)
03-28 15:47:34.470: W/System.err(3185): at libcore.io.IoBridge.bind(IoBridge.java:87)
03-28 15:47:34.470: W/System.err(3185): ... 5 more
03-28 15:47:34.470: W/System.err(3185): java.lang.NullPointerException
03-28 15:47:34.490: W/System.err(3185): at <path>Provider$server.run(<filename>.java:315)
03-28 15:47:34.490: W/System.err(3185): at java.lang.Thread.run(Thread.java:856)
代码:
class server implements Runnable {
public void run() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(10000);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
// Log.d("Recieving ", "Server Socket Created");
try {
while(true) {
// Blocks until a connection occurs:
try {
Socket client = serverSocket.accept();
//Log.d("Recieving ", "Client request accepted");
str_proc tk = new str_proc(client);
tk.start();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Log.d("Recieving ", "Problem creating socket for listening");
}
}//while true loop ends
}catch (Exception e){
e.printStackTrace();
}
}
}