无法使用 AVD 在 Window7 上绑定端口 1131
我在 Windows7 上的 Android AVD 中使用以下 java 代码来创建 serverPort = 1131; 的服务器;
try {
ServerSocket serverSocket = new ServerSocket(serverPort);
serverSocket.setReuseAddress(true);
while(isRunning){
try {
final Socket socket = serverSocket.accept();
DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();
serverConnection.bind(socket, new BasicHttpParams());
httpService.handleRequest(serverConnection, httpContext);
serverConnection.shutdown();
} catch (IOException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
}
}
serverSocket.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
我收到以下异常:-
01-18 06:30:03.381: W/System.err(1494): java.net.BindException: bind failed: EACCES (Permission denied)
我的计算机上的防火墙已关闭并且无法正常工作。我还为此添加了特殊规则。 我需要做一些特殊的事情才能在 Window7 上的 AVD 上运行服务器吗?
请帮忙。
谢谢
I am using the following java code in Android AVD on Windows7 to create my server with serverPort = 1131;
try {
ServerSocket serverSocket = new ServerSocket(serverPort);
serverSocket.setReuseAddress(true);
while(isRunning){
try {
final Socket socket = serverSocket.accept();
DefaultHttpServerConnection serverConnection = new DefaultHttpServerConnection();
serverConnection.bind(socket, new BasicHttpParams());
httpService.handleRequest(serverConnection, httpContext);
serverConnection.shutdown();
} catch (IOException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
}
}
serverSocket.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
I get the following exception :-
01-18 06:30:03.381: W/System.err(1494): java.net.BindException: bind failed: EACCES (Permission denied)
The firewall on my machine is off & I have added special rules for that as well.
Do I need to do something special for running server on AVD on Window7?
Kindly help.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 MSDN 网站上找到了以下内容(在网站上搜索“bind”和“EACCES”):
因此,如果我们假设 JVM 本机库将
WSAEACCES
映射到此异常,则有两种明显可能的解释:这是基于权限的事情。 ADV 没有权限绑定到该端口。
某些其他应用程序已使用 SO_EXCLUSIVEADDRUSE 套接字选项绑定到该端口。
IMO,这两种解释都是合理的。 (或者可能是别的东西......)
I found the following on the MSDN site (search the site for "bind" and "EACCES"):
Thus, if we assume that the JVM native libraries map
WSAEACCES
to this exception, there are two obvious possible explanations:This is a permissions-based thing. ADV doesn't have permission to bind to that port.
Some other application has already bound to the port with the SO_EXCLUSIVEADDRUSE socket option.
IMO, either explanation is plausible. (Or it could be something else ...)