Android Emulator can not connect to SailsJs server via Socket.IO - android

I am developing an Android app. I would like it to communicate with a SailsJS server via SocketIO. I am using socket.io for Android(com.github.nkzawa:socket.io-client) as the socket.io library in the android app.
I run it on an emulator while doing the development. The initialization code is as below:
private Socket mSocket;
{
try {
mSocket = IO.socket(Config.SERVER_URL);
} catch (URISyntaxException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
Config.SERVER_URL is set to be "http://10.0.2.2:1337".
It always reports "connect_error". What should I do to get it connected?

Related

SignalR giving problems in Android 9.0

I need to start a connection using SignalR hubProxy class, everything works fine till API 25 but above 25 it gives this error:
Failed to finalize session : INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113
code I'm Using
HubConnection hubConnection = new HubConnection(hubUrl);
HubProxy hubProxy = hubConnection.createHubProxy("hubName");
try {
SignalRFuture<Void> awaitConnection;
awaitConnection = hubConnection.start(new ServerSentEventsTransport(hubConnection.getLogger()));
awaitConnection.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
I tried to resolve it by following this answer, but it does not provide hubProxy class. so I cannot use it.
Please tell me how to fix this error.

In what ports can we run a service on android

My situation:
I'm trying to create an android app using unity that has a server running, so I can call the service from a PC.
However, when I try to connect to the server I get the error message:
SocketException: No connection could be made because the target machine actively refused it.
System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy)
System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP)
System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point)
System.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port)
Doing ping on the IP Address is fine, so the host is reachable, as far as I know android devices don't have firewalls, so my guess it is a problem with the port.
Currently I'm trying to run the service on port 9096, which works if I just run the application in the editor. Is this a valid port for android?
If not, what would be a valid one?
Do you have any other ideas on what the problem could be?
Thank you.
Additional info:
The device is Google Tango and I want to use Thrift to create a server and access the location of the device from a windows coomputer.
========================================================
UPDATE: included code for server and client
public void startServerService()
{
try
{
TangoService.Processor processor = new TangoService.Processor(this);
serverTransport = new TServerSocket(9096);
server = new TThreadPoolServer(processor, serverTransport);
Debug.Log("Starting the server...");
server.Serve();
}
catch (UnityException e)
{
Debug.Log(e);
}
}
void startClient()
{
try{
TTransport transport = new TSocket(ipAddress, 9096);
transport.Open ();
TProtocol protocol = new TBinaryProtocol(transport);
client=new TangoService.Client(protocol);
}
catch(UnityException e)
{
Debug.Log(e);
}
}

Android Socket.IO - Connect to a Nodejs server from an android app (works on a browser)?

I have a NodeJs server and I want to connect it with my Andoird native app thru socket.io.
When I use the domain from demo (demo: http://socket.io/blog/native-socket-io-and-android/) it works, and the socket is connected
private Socket mSocket;
{
try {
mSocket = IO.socket("http://chat.socket.io");
} catch (URISyntaxException e) {}
}
mSocket.connect();
However, when I try my own server address the socket does not connect
private Socket mSocket;
{
try {
mSocket = IO.socket("http://ec2-23-23-240-76....:7003/");
} catch (URISyntaxException e) {}
}
mSocket.connect();
Someone have any idea why?
Thanks!

android TCP socket (Check if available)

I have an android app that connects to a TCP server.
I made a button to check is the server is available.
If i click the button it keeps trying to connect and doesn't go to the Exception.
Code:
try {
Socket s = new Socket("192.168.xxx.xx",xxxxx);
available = true;
s.close();
} catch (IOException e) {
//show error toast.
}

HTTPS Server with Jetty on Android

Im trying to get a HTTPS Server running in my Android App. I've decided to do it with Jetty (Version 7.0.2). My Problem is that I can't get the Server working. The HTTP Connector works fine, but whenever I try to connect to the HTTPS Connector the Android Browser tells me:
Connection Problem: Couldn't establish a secure connection.
Heres the Code I'm using:
server = new Server(8080);
SelectChannelConnector connector0 = new SelectChannelConnector();
connector0.setPort(8080);
connector0.setMaxIdleTime(30000);
connector0.setRequestHeaderSize(8192);
SslSelectChannelConnector ssl_connector = new SslSelectChannelConnector();
ssl_connector.setPort(8443);
SslContextFactory cf = ssl_connector.getSslContextFactory();
cf.setKeyStore("keystore");
cf.setKeyStorePassword("password");
cf.setKeyManagerPassword("password");
server.setConnectors(new Connector[]{ connector0, connector1});
server.setHandler(new HelloHandler());
try {
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
As mentioned before the SelectChannelConnector works fine, but the SslSelectChannelConnector doesn't. I'm using a BKS keystore created by portecle. Is there anything wrong in my Code? Or is there a problem with Android?
Thanks for your help

Categories

Resources