SignalR android SDK only works on WiFi connection - android

To be clear, this question is referencing the Android SDK for SignalR...not SignalR running in a browser on an android device.
For some reason, I can not establish a connection to the server when using my wireless data network (3g). I'm able to connect to my server via web services and receive a JSON string of data, but SignalR will not connect.
SignalRFuture<Void> awaitConnection = connection.start();
try {
awaitConnection.get(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// Handle ...
} catch (ExecutionException e) {
// Handle ...
} catch (TimeoutException e) {
Log.d(TAGSR,"it timed out");
e.printStackTrace();
}
this hits the timeout exception always when I'm NOT on WiFi...even if I bump it up to a minute +. What's weird is that as soon as it times out, the other aforementioned data loads instantly. If I turn my WiFi on my phone, this connects no problem at all.
Using the same SignalR connection with my browser, I'm able to connect via 3g with no problems at all...it's only the Android SDK version that pukes unless it's on WiFi. Is there some built in mechanism to the SDK that requires a certain connection speed? If so, is there a way to override that value? My 3g ain't a ferrari, but it's fast enough to work over the web version, and work fine at that....
any ideas?
TIA

no idea why, but it appears that it's the transport selection that's causing a failure on 3g.
when I comment out one or the other (serversentevents or longpolling) in AutomaticTransport, it works fine...
private void initialize(Logger logger) {
mTransports = new ArrayList<ClientTransport>();
mTransports.add(new ServerSentEventsTransport(logger));
//mTransports.add(new LongPollingTransport(logger));
}

Related

Android app is not working frequently in Reliance JIO 4G connection

I have an android app which is working completely fine in WiFi and 3G connection of all operators except Reliance Jio.
However, I have found that Sometimes the android app is not connecting to my HTTPS web-services when Reliance JIO 4G connection is used, but the same set of HTTPS web-services are working perfectly without any delay when the device is connected to other service providers.
You should check whether the user has an active internet connection before making the request.
use this method to check internet availability only make a request if this returns true, otherwise, toast them internet is not available.
public static boolean isInternetAvailable() {
try {
InetAddress ipAddr = InetAddress.getByName("google.com"); //You can replace it with your domain name
return !ipAddr.equals("");
} catch (Exception e) {
return false;
}
}

Frequent HttphostConnectException

I uploaded my app recently to Google Playstore. I used Error Reporter to track the crashes. App is working fine but very frequently I get HttpHostConnectException. Before making every web-call, I checked for Internet Connection. Are there any other reasons for the cause of this exception? How can it be avoided?
P.S. I never get this exception while testing/debugging my app.
HttpHostConnectException is thrown when connection cannot be established to a remote host on a specific port.
Before making every web-call, I checked for Internet Connection.
Checking internet connection is not a full-proof way to decide that the host is reachable. In many instances like using wifi, the device is connected to your router while the router is not connected to the internet. Checking internet connection using classes like ConnectivityManager in such cases returns true but the actual connection is false.
The solution is to check if your host is actually reachable using any http methods.
public boolean isInternetAvailable() {
try {
InetAddress ipAddr = InetAddress.getByName("google.com"); //You can replace it with your name
if (ipAddr.equals("")) {
return false;
} else {
return true;
}
} catch (Exception e) {
return false;
}
}
The above code is taken from this SO post.
I used AsyncHttpClient to handle all my webcalls. It handles my case perfectly. It directly takes to onFailure() on getting HttphostConnectException.

Java server socket not accepting connection over tethered connection

I've written a small file transfer program for android using standard Java sockets. The program works fine except for the following case:
I connect two android devices A and B over WiFi tethering connection. Device A is sharing the connection (enabled as wireless hotspot). When I run java server on A and client on B, the program works okay but when I run the server on device B, it can't accept any socket binding request from A. It doesn't throw any exception. Seems like the request is not reaching the server! However, both the devices are connected (ping test is okay in both directions). Can't I run socket server on a device connected as hotspot client? I thought once the networking is setup correctly, the application would work in any direction.
Also, Wireshark traces reveal nothing. What am I missing here? Please help! Here are my code snippets:
Server side (waiting for client connection):
while (true) {
try {
socket = serversocket.accept();
Runnable connectionHandler = new ConnectionHandler(
socket, fileArray, filepathNameArray,
SenderActivity.this, userID, handler);
new Thread(connectionHandler).start();
userID = userID + 1;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I would appreciate any kind of help! Thanks in advance.

Kryonet disconnects client 1 as soon as client 2 connects

I've worked before with Kryonet doing 1-to-1 communication and it worked nicely.
Now I'm doing a more 'standard' project where we'll have 1 server and several clients to connect to it.
The issue I'm having is as described in the title: client 1 connects, no problem. Then I ask for client 2 to connect and immediately client 1 disconnects. Somehow the server doesn't want to keep more than one simultaneous connection.
A couple of times we managed to have 2 connected and then whenever the 3rd connects the other drops.
Running on several different devices all ICS+ (galaxy nexus, tab2, SGS3).
The codes I'm using are very much like the examples:
server side:
server = new Server();
ServiceData.RegisterKryo(server.getKryo());
server.addListener(new MyServerListener());
try {
server.bind(ServiceData.SERVER_PORT_TCP);
server.start();
} catch (IOException e) {
Log.e(TAG, "IOException. Failed to start server. " + e.getMessage());
MyServer.this.stopSelf();
}
And then client side:
final String ip = intent.getExtras().getString(KEY_SERVER_IP);
listener = new MyClientListener();
client = new Client();
client.start();
ServiceData.RegisterKryo(client.getKryo());
client.addListener(listener);
try {
client.connect(5000, ip, ServiceData.SERVER_PORT_TCP);
} catch (IOException e) {
Log.e(TAG, "IOException. Failed to start client. " + e.getMessage() + "\n");
e.printStackTrace();
MyClient.this.stopSelf();
}
the listeners at the moment are just Log.v(TAG, "something happened); and I've also enabled all the logs from the Kryonet library with com.esotericsoftware.minlog.Log.set(com.esotericsoftware.minlog.Log.LEVEL_TRACE); so I can see when it's connecting and when it's disconnecting.
I receive two different messages upon disconnection:
DEBUG: [kryonet] Connection 3 timed out.
and
DEBUG: [kryonet] Unable to read TCP from:
really not sure what's on here and any help will be appreciated.
edit:
a bit more info:
I've realised that between INFO: [kryonet] Connection 3 connected: /192.168.0.104 and my listener receive the connected callback, it's taking around 9 seconds! Very odd.
To whom might get into the same issue.
Apparently it's an Android limitation (probably imposed because it's a mobile device)
I just moved the Server code to a normal Java application .jar and let the Android clients connect to the PC and it all works fine now. Until now tested with 6 devices connected with no problems.

Android Developing - Slow Internet Connection via 3G

I'm developing a Client/Server Application with Android/Rails and Communication via REST Json
When I'm testing my App via Emulator, all works fine.
Also when I deploy the app on my phone with WIFI on it works and the speed is ok.
But when I disconnect from WIFI and use the 3G connection, the phone becomes incredible Slow and it takes Minutes du get one JSON Response from the Server.
I'ved debug a little bit and the Problem seems to be the HTTPClient, which execute Method takes ulta long.
Other Apps with Network Access are working perfectly.
Any suggestions what to do?
HTC Magic
Android 1.6
My Http Connection Code:
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet("URL");
try {
client.execute(get);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
SOLVED: Some Problems with the Port. I changed my Server Port from 3000 to 80 and it works just fine. Thanks for the Comment, that was the great Hint :).
Thanks to Chris Stratton
Move to an area with better mobile data coverage?

Categories

Resources