开发者

Web Server on Android phone

I'm trying to set up a web server using the Restlet framework on my Android phone. My idea is to build a game where one phone creates some markers on a map which then can be transferred directly to other phones using rest. At first (and for simplicity) I want to transfer a List of Objects.

Running a server on my computer seems to work fine, but when I transfer the code to my Android application, it won't start the server. Here is the code:

Component serverComponent = new Component();
serverComponent.getServers().add(Protocol.HTTP, 80);  
final Router ro开发者_如何学运维uter = new Router(serverComponent.getContext().createChildContext());  
router.attach("/gamedata", GameDataResourceServer.class);  
serverComponent.getDefaultHost().attach(router);  
serverComponent.start();  

When the line serverComponent.start(); is executed, this Exception is thrown:

java.net.BindException: Permission denied (maybe missing INTERNET permission), although the internet permission is in the manifest file. Searching for some tutorials didn't help either. The result are either client applications or very complicated scenarios.

Could someone give an example for a simple application?


In Unix-type environments you typically need root access to bind to a TCP port below 1024. You're trying to bind to port 80, and unless you run this code as root the OS will prevent the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜