I'm working on a project where my android application should behave as a server for other android clients .. I'm using Eneter messaging framework which uses Sockets and Google Protobuf .. on wifi everything works like a charm but once I switch to 3g network (try to start server using phone's 3g public ip adress and port 80/81) I get the following error : EACCES (Permission denied)
E/EneterMessaging: ~24216 eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening TcpListenerProvider failed to start listening.
Exception:
java.net.BindException: bind failed: EACCES (Permission denied)
libcore.io.IoBridge.bind(IoBridge.java:99)
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:132)
java.net.ServerSocket.bind(ServerSocket.java:335)
eneter.messaging.messagingsystems.tcpmessagingsystem.NoneSecurityServerFactory.createServerSocket(NoneSecurityServerFactory.java:51)
eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening(TcpListenerProvider.java:123)
eneter.messaging.messagingsystems.tcpmessagingsystem.TcpInputConnector.startListening(TcpInputConnector.java:134)
eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening(DefaultDuplexInputChannel.java:96)
eneter.messaging.infrastructure.attachable.internal.AttachableDuplexInputChannelBase.attachDuplexInputChannel(AttachableDuplexInputChannelBase.java:40)
com.inactivity.magamine.teatime.services.TCPService.StartServer(TCPService.java:261)
com.inactivity.magamine.teatime.services.TCPService$6.run(TCPService.java:279)
java.lang.Thread.run(Thread.java:818)
I have these permissions in my manifest:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET"/>
and this is the code that starts the server:
public void StartServer() throws Exception
{
// Create sender sending MyRequest and as a response receiving MyResponse
// Instantiate Protocol Buffer based serializer.
ISerializer aSerializer = new ProtoBufSerializer();
// Create sender sending MyRequest and as a response receiving MyResponse
// The sender will use Protocol Buffers to serialize/deserialize messages.
IDuplexTypedMessagesFactory aRecieverFactory = new DuplexTypedMessagesFactory(aSerializer);
myReceiver = aRecieverFactory.createDuplexTypedMessageReceiver(MessageDeclarations.MyMsg.class, MessageDeclarations.MyMsg.class);
myReceiver.messageReceived().subscribe(myOnRequestHandler);
if(aMessaging == null)aMessaging = new TcpMessagingSystemFactory();
IDuplexInputChannel anInputChannel
= aMessaging.createDuplexInputChannel(Service_URL);//Service_URL = "tcp://xxx.xxx.x.xx:80/ with public ip adress
// Attach the output channel to the sender and be able to send
// messages and receive responses.
myReceiver.attachDuplexInputChannel(anInputChannel);
isConnected = true;
showNotification("Server Started","url: "+Service_URL,Color.GREEN);
}
The exception occurs on
myReceiver.attachDuplexInputChannel(anInputChannel);
Thats where Eneter starts the socket server.
EDIT: From this I found that to bind on ports < 1024 you need root privileges. So I tried ports like 1025, 8080, 8081 , I now get this exception instead: Cannot assign requested address, is it that I cant use 3G network public ip adress to start a socket server or am I missing something ?
E/EneterMessaging: ~25710 eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening DefaultDuplexInputChannel 'tcp://105.66.131.38:8080/' failed to start listening.
Exception:
java.net.BindException: bind failed: EADDRNOTAVAIL (Cannot assign requested address)
libcore.io.IoBridge.bind(IoBridge.java:99)
java.net.PlainSocketImpl.bind(PlainSocketImpl.java:132)
java.net.ServerSocket.bind(ServerSocket.java:335)
eneter.messaging.messagingsystems.tcpmessagingsystem.NoneSecurityServerFactory.createServerSocket(NoneSecurityServerFactory.java:51)
eneter.messaging.messagingsystems.tcpmessagingsystem.internal.TcpListenerProvider.startListening(TcpListenerProvider.java:123)
eneter.messaging.messagingsystems.tcpmessagingsystem.TcpInputConnector.startListening(TcpInputConnector.java:134)
eneter.messaging.messagingsystems.simplemessagingsystembase.internal.DefaultDuplexInputChannel.startListening(DefaultDuplexInputChannel.java:96)
eneter.messaging.infrastructure.attachable.internal.AttachableDuplexInputChannelBase.attachDuplexInputChannel(AttachableDuplexInputChannelBase.java:40)
com.inactivity.magamine.teatime.services.TCPService.StartServer(TCPService.java:261)
com.inactivity.magamine.teatime.services.TCPService$6.run(TCPService.java:279)
java.lang.Thread.run(Thread.java:818)
I will appreciate your help.
Kindly