koush / androidasync Goto Github PK
View Code? Open in Web Editor NEWAsynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
License: Other
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
License: Other
Hello
Is there anyway to get "progress" about a POST upload call?
TIA
I can't connect to my server using socket.io, but I can connect to koush.clockworkmod.com:8080
. I think this may have something to do with the version ?
Can socket switch from web-socket to xhr if web-socket does not work on certain situations?
Is there an option to switch to xhr and back according to the network conditions (WiFi,3G)?
In this case, androidasync drops the connection after receiving the first packets.
I was using (ion ๐ ) downloading pictures from cloudfront and when a cache miss happens, cloudfront goes to the origin server which served chunked data, and serves it back without transfer-encoding or content-length headers. We fixed the issue server-side by setting content-length on the server.
Typically, it downloads 15Kb of a 90Kb picture and then drops the connection. (I saw this with wireshark)
Ion then tries to decode the partial data but skia fails as it cant decode partial pictures.
From this doc, I assume it should wait for the server to close the connection.
UrlImageViewHelper and Picasso are not affected.
I tried to pinpoint the faulty code and found it might be around line 178 in AsyncHttpResponseImpl but I am not sure.
When the socket.io
connection has dropped, and acknowledge
from that connection is invoked, NullPointerException
is raised.
Currently the workaround is to surround acknowledge()
with try/catch
about:
W/System.err: javax.net.ssl.SSLException: Fatal alert received bad_record_mac
W/System.err: at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:485)
W/System.err: at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
W/System.err: at com.koushikdutta.async.AsyncSSLSocketWrapper$1.onDataAvailable(AsyncSSLSocketWrapper.java:91)
W/System.err: at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:33)
W/System.err: at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:61)
W/System.err: at com.koushikdutta.async.Util.emitAllData(Util.java:20)
W/System.err: at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:170)
W/System.err: at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:805)
W/System.err: at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:664)
W/System.err: at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:34)
W/System.err: at com.koushikdutta.async.AsyncServer$14.run(AsyncServer.java:612)
you said that forcing SSLv3 could solve it. but how do I force it?
TIA
I'm pretty sure this is not an issue with the program, but with my usage of it ...
07-20 00:44:50.183: ASSERT/NetworkStats(93): problem reading network stats
java.lang.IllegalStateException: problem parsing line: null
at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:313)
at com.android.server.NetworkManagementService.getNetworkStatsUidDetail(NetworkManagementService.java:1271)
at com.android.server.net.NetworkStatsService.performPollLocked(NetworkStatsService.java:810)
at com.android.server.net.NetworkStatsService.updateIfacesLocked(NetworkStatsService.java:721)
at com.android.server.net.NetworkStatsService.updateIfaces(NetworkStatsService.java:699)
at com.android.server.net.NetworkStatsService.access$000(NetworkStatsService.java:128)
at com.android.server.net.NetworkStatsService$1.onReceive(NetworkStatsService.java:589)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:728)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: java.io.FileNotFoundException: /proc/net/xt_qtaguid/stats: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:406)
at java.io.FileInputStream.(FileInputStream.java:78)
at java.io.FileReader.(FileReader.java:42)
at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:272)
... 11 more
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:98)
at libcore.io.IoBridge.open(IoBridge.java:390)
... 14 more
I have not (yet) given my app permission to read or write external storage - this is presumably the cause? But is it inteded that the logged exception "java.lang.IllegalStateException: problem parsing line: null" should occur?
On a completely different note, I don't suppose there are any sample apps available that demonstrate how to connect and send and receive simple tcp/ip packets? No http, no json, no ssl ...
Apologies if this is a newbie misunderstanding, but is there currently no way to receive messages when hosting a WebSocket server?
I can't find any callback that fires for receiving WebSocket messages (on the server side) after the initial onConnected(). I tried using WebSocket.setStringCallback() but think that's intended for the client side.
Hi,
I'm trying to do the following Socket.IO JavaScript code with the help of your library:
emit('subscribe', { 'channel' : 'test' });
I've tried doing this on Android using a JSONObject:
JSONObject args = new JSONObject():
args.put("channel", "test");
JSONObject message = new JSONObject();
message.put("name", "subscribe");
message.put("args", args);
client.emit(message, new Acknowlegde() {...})
I also tried using
client.of("test", callback)
But none of these worked. How am I supposed to add arguments to an emit call, like in JavaScript? I am trying to join a room/channel called test.
Hi,is there any trouble if you using the android's DatagramChannel.receive()
to get some data?
I found that the receive() can not get any message from the remote peer,but the read(),method can,
Hi,
I have an app using socket.io(nodejs) and most of my socket.on methods(server side) is using the callback function "fn" to retrieve data to the client. There's a way to use those same callback function "fn" to retrieve data to my AndroidAsync client?
Thank you!
ps: sorry about my english.
Hi,
I'm not sure what I'm doing wrong but I'm getting the following error when trying to connect to my socket.io server:
System.err W java.lang.NumberFormatException: Invalid int: "//fonts.googleapis.com/css?family=Open+Sans"
System.err W at java.lang.Integer.invalidInt(Integer.java:138)
System.err W at java.lang.Integer.parse(Integer.java:375)
System.err W at java.lang.Integer.parseInt(Integer.java:366)
System.err W at java.lang.Integer.parseInt(Integer.java:332)
System.err W at com.koushikdutta.async.http.socketio.SocketIOConnection$1.onCompleted(SocketIOConnection.java:112)
System.err W at com.koushikdutta.async.http.socketio.SocketIOConnection$1.onCompleted(SocketIOConnection.java:100)
System.err W at com.koushikdutta.async.http.AsyncHttpClient.invokeWithAffinity(AsyncHttpClient.java:443)
System.err W at com.koushikdutta.async.http.AsyncHttpClient.access$500(AsyncHttpClient.java:40)
System.err W at com.koushikdutta.async.http.AsyncHttpClient$4.run(AsyncHttpClient.java:450)
System.err W at com.koushikdutta.async.AsyncServer.lockAndRunQueue(AsyncServer.java:749)
System.err W at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:760)
System.err W at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:664)
System.err W at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:34)
System.err W at com.koushikdutta.async.AsyncServer$14.run(AsyncServer.java:612)
I'm using a very simple socket.io server (the one from the socket.io site):
var io = require('socket.io').listen(8080);
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
It works fine when connecting from a webbrowser.
And this is the Android code I'm using (pretty much taken from the readme):
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), wsuri, new ConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, SocketIOClient client) {
if (ex != null) {
Log.i(TAG, "ex is not null!");
ex.printStackTrace();
return;
}
client.setStringCallback(new StringCallback() {
@Override
public void onString(String string, Acknowledge acknowledge) {
System.out.println(string);
}
});
client.setJSONCallback(new JSONCallback() {
@Override
public void onJSON(JSONObject json, Acknowledge acknowledge) {
System.out.println("json: " + json.toString());
}
});
}
});
I'm not sure if I'm doing something wrong here. I tried it yesterday with version 1.1.3 and today with the new 1.1.4.
Thanks!
Attempting to read the user-agent in the onRequest
callback of AsyncHttpServer
results in null
.
mServer = new AsyncHttpServer();
mServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request,
AsyncHttpServerResponse response) {
String userAgent = request.getHeaders().getUserAgent();
response.send("Hello World!");
}
});
However, using the RawHeaders works fine:
userAgent = request.getHeaders().getHeaders().get("User-Agent");
There is a native library but that seems to be overly complicated to use and target audio/video.
An abstract interface for data connections could be very useful for mobile game development
When in socket.io i do socket.emit("myevent")
without any argument the onEvent callback is not triggered.
p.s.: thank you for this amazing library, even if it's very young it's pretty stable and even if some features are missing the implemented ones work very well.
I use post method in this way:
String my_way() {
AsyncHttpPost httpPost = new AsyncHttpPost("URL");
httpPost.setBody(new StringBody("StringBody"));
Future f = AsyncHttpClient.getDefaultInstance().executeString(httpPost);
String s = f.get();
return s;
}
It returns what i want most of time. But if i call it to frequently, it results s = "".
for(int i=0;i<10;i++) {
system.out.println(my_way());
}
results:
"Right Message"
""
"Right Message"
""
"Right Message"
""
"Right Message"
""
"Right Message"
""
I am sure that the server side is ok, because another lib has pass this test.
It happens even i use it like this
for(int i=0;i<10;i++) {
thread.sleep(1000);
system.out.println(my_way());
}
I am migrating my socket.io implementation from this https://github.com/Gottox/socket.io-java-client to AndroidAsync. I couldn't find the alternate for certain use-cases that i used in that library. Please help me with the following use-cases.
1.How to check whether socket.io is connected or not?
2.How to disconnect socket connection?
3.How to reconnect socket?
Hi,
when I call cancel() on the Future I get from getFile(...), the download is not cancelled when the download is running already, only when it is called directly after the getFile() call:
AsyncHttpClient client = AsyncHttpClient.getDefaultInstance();
Future futureFile = client.getFile(url, path, callback);
futureFile.cancel(); -> works
SystemClock.sleep(1000);
futureFile.cancel(); -> does not work anymore (first cancel() is removed of course)
Regards,
Marc
Hi again :)
I'm having this exception:
I'm uploading a file, it finish to upload and the file is uploaded ok. but the callback comes with an exception as a parameter.
any idea?
Thanks!
W/System.err( 2128): java.lang.NullPointerException
W/System.err( 2128): at ajo.onDataAvailable(SourceFile:239)
W/System.err( 2128): at com.koushikdutta.async.DataEmitterReader.a(SourceFile:23)
W/System.err( 2128): at com.koushikdutta.async.DataEmitterReader.onDataAvailable(SourceFile:38)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at com.koushikdutta.async.FilteredDataEmitter.onDataAvailable(SourceFile:50)
W/System.err( 2128): at com.koushikdutta.async.http.filter.ContentLengthFilter.onDataAvailable(SourceFile:31)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at aik.onDataAvailable(SourceFile:113)
W/System.err( 2128): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(SourceFile:33)
W/System.err( 2128): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(SourceFile:61)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at com.koushikdutta.async.AsyncNetworkSocket.b(SourceFile:170)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.c(SourceFile:805)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.b(SourceFile:664)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.a(SourceFile:34)
W/System.err( 2128): at air.run(SourceFile:612)
W/System.err( 2128): java.lang.NullPointerException
W/System.err( 2128): at com.koushikdutta.async.DataEmitterReader.a(SourceFile:23)
W/System.err( 2128): at com.koushikdutta.async.DataEmitterReader.onDataAvailable(SourceFile:38)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at com.koushikdutta.async.FilteredDataEmitter.onDataAvailable(SourceFile:50)
W/System.err( 2128): at com.koushikdutta.async.http.filter.ContentLengthFilter.onDataAvailable(SourceFile:31)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at aik.onDataAvailable(SourceFile:113)
W/System.err( 2128): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(SourceFile:33)
W/System.err( 2128): at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(SourceFile:61)
W/System.err( 2128): at com.koushikdutta.async.Util.emitAllData(SourceFile:20)
W/System.err( 2128): at com.koushikdutta.async.AsyncNetworkSocket.b(SourceFile:170)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.c(SourceFile:805)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.b(SourceFile:664)
W/System.err( 2128): at com.koushikdutta.async.AsyncServer.a(SourceFile:34)
According to Socket.IO HTTP requests:
User-defined query components are allowed. For example, "?t=1238141910&token=mytoken" is a valid query.
But I can't find such as setQuery or setParams in SocketIORequest class
I am running the server on android and trying to connect to it from macbook on same network.
Getting the following error on chrome and firefox:
WebSocket connection to 'ws://192.168.0.102:8888/echo' failed: One or more reserved bits are on: reserved1 = 1, reserved2 = 0, reserved3 = 0
Firefox:
[21:25:49.381] The connection to ws://192.168.0.102:8888/echo was interrupted while the page was loading. @ http://192.168.0.102:8888/:7
Server code
mServer = new AsyncHttpServer();
mServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send(readStream(getResources().openRawResource(R.raw.index)));
}
});
mServer.websocket("/echo", new WebSocketRequestCallback() {
@Override
public void onConnected(WebSocket webSocket, RequestHeaders headers) {
webSocket.setStringCallback(new StringCallback() {
@Override
public void onStringAvailable(String s) {
Log.e("Socket", "msg : " + s);
}
});
}
});
mServer.listen(8888);
index.html
<html>
<head>
<title>Web Socket test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function initws() {
var connection = new WebSocket('ws://192.168.0.102:8888/echo', "chat");
// When the connection is open, send some data to the server
connection.onopen = function () {
console.log('connected'); // Send the message 'Ping' to the server
};
// Log errors
connection.onerror = function (error) {
console.log('WebSocket Error', error);
};
// Log messages from the server
connection.onmessage = function (e) {
console.log("Message", e);
};
}
</script>
</head>
<body>
<h1>Web Socket test</h1>
<button onclick="initws()">Connect</button>
Update:
Same error on chrome on android itself, so it should not be a firewall issue.
Also the error happens just after onopen as I am getting the 'connected' message. And if I send some message back from index.html in onopen, it is received by the server
Is there a code sample to connect to a server via websockets? I'm trying to connect to a sockjs server but I keep receiving timeouts:
AsyncHttpClient.getDefaultInstance().websocket("ws://ddptesttp.meteor.com/websocket", null, new AsyncHttpClient.WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket webSocket) {
if (ex != null) {
System.out.println("I got an error");
ex.printStackTrace();
return;
}
webSocket.setStringCallback(new WebSocket.StringCallback() {
public void onStringAvailable(String s) {
System.out.println("I got: " + s);
}
});
}
});
WebSockets work in all browsers except IE10, this error in browser: "WebSocket Error: Incorrect HTTP response. Status code 404, Not Found" and this in app:
07-29 19:36:36.624: E/NIO(8764): Unhandled exception
07-29 19:36:36.624: E/NIO(8764): java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)
07-29 19:36:36.624: E/NIO(8764): at libcore.io.IoBridge.maybeThrowAfterRecvfrom(IoBridge.java)
07-29 19:36:36.624: E/NIO(8764): at libcore.io.IoBridge.recvfrom(IoBridge.java)
07-29 19:36:36.624: E/NIO(8764): at java.nio.SocketChannelImpl.readImpl(SocketChannelImpl.java)
07-29 19:36:36.624: E/NIO(8764): at java.nio.SocketChannelImpl.read(SocketChannelImpl.java)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.SocketChannelWrapper.read(SocketChannelWrapper.java:24)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:151)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:803)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:662)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.AsyncServer.access$5(AsyncServer.java:651)
07-29 19:36:36.624: E/NIO(8764): at com.koushikdutta.async.AsyncServer$14.run(AsyncServer.java:610)
07-29 19:36:36.624: E/NIO(8764): Caused by: libcore.io.ErrnoException: recvfrom failed: ECONNRESET (Connection reset by peer)
07-29 19:36:36.624: E/NIO(8764): at libcore.io.Posix.recvfromBytes(Native Method)
07-29 19:36:36.624: E/NIO(8764): at libcore.io.Posix.recvfrom(Posix.java)
07-29 19:36:36.624: E/NIO(8764): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java)
07-29 19:36:36.624: E/NIO(8764): ... 9 more
I have created a websocket server with this library, but I can't seem to find any way to accept streaming data on a websocket connection.
Is there a way to do this with AndroidAsync?
Is this code working on API 8 devices?
I tested on emulator and have problems with this issue:
http://code.google.com/p/android/issues/detail?id=9431
java.lang.System.setProperty("java.net.preferIPv4Stack", "true");
java.lang.System.setProperty("java.net.preferIPv6Addresses", "false");
Even if I set this property something else is crashing...
in case i am sending json request
the code in httpUtil :
if (JSONObjectBody.CONTENT_TYPE.equals(ct)) {
return new JSONObjectBody();
}
does not check if its a json object or array so in case its array like [{ "a":"b"} ]
request.getBody() will return null as it will not parse the JSONArray
unless i will change the code like
if (JSONObjectBody.CONTENT_TYPE.equals(ct)) {
return new JSONArrayBody ();
}
but now i wil get null value in case the request body is json object and not json array
how to set cookies in headers while connecting to socket?
Is it possible to set reconnectDelay manually?
In my case, let's say android lost connection. I want to bring back the connection ASAP.
Maybe there is another more appropriate solution to this problem ?
Hi,
I just downloaded the latest version (commit 0a1bf13). and there JSONRequestBody is missing the get() method from DataParser. Is this work in progress? Which version can you recommend for usage?
Thx in advance,
Marc
In https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/http/body/MultipartFormDataBody.java there's a method to addFilePart to the body but is there a way to get the File part out of the Body?
I'm writing a system involves multiple Android devices and I want to upload file from one device to another, is it possible for me to use this class for this purpose?
I am having a problem when cancelling futures that I obtained using the format,
Future future = AsyncHttpClient.getDefaultInstance().get(getUrl, new AsyncHttpClient.StringCallback() {...} });
If the server does not respond, the user can click back twice to cancel the network operation. More often than not, this causes the following crash:
And if I surround the above with a null check, I get this crash instead:
I am not sure why the callback immediately becomes null when issuing a cancel but that can be fixed fairly easily; however, I'm stumped as to how to prevent the crash at the assert without removing the entire call. I guess I'm curious if I am doing something wrong in the first place. I'm assuming the reason for returning a future was to give the ability to cancel, but is there something else I should do to prevent the crash like some cleanup of the prior operation?
Hello.
The "the latest JAR" in the readme is broken.
Thanks, : )
i got a local socket.io server, that gave a response on connect with you lib.
but than i became
INFO/AsyncHttpSocket(3876): com.koushikdutta.async.http.AsyncSSLSocketMiddleware Not keeping non-owned socket: null
and than i send text to the socket for the android device and there is no response...
public void socketConnect(){
String socketUrl = "http://192.168.0.117:7788";
Log.d("Socket ", " try to connect "+ socketUrl +" " + UserData.getInstance().getToken());
SocketIOClient.SocketIORequest request = new SocketIOClient.SocketIORequest( socketUrl );
request.setHeader("token", UserData.getInstance().getToken());
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), request, new SocketIOClient.SocketIOConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, SocketIOClient client) {
if (ex != null) {
Log.d("Socket", "no connection " + ex.getMessage());
ex.printStackTrace();
return;
}
Log.d("Socket", "maybe connected?");
client.setStringCallback(new SocketIOClient.StringCallback() {
@Override
public void onString(String string) {
Log.d("Socket", "string... conn. lalalal");
System.out.println(string);
}
});
client.setEventCallback(new EventCallback() {
@Override
public void onEvent(String event, org.json.JSONArray arguments) {
//To change body of implemented methods use File | Settings | File Templates.
Log.d("Socket", "Event");
}
});
client.setJSONCallback(new SocketIOClient.JSONCallback() {
@Override
public void onJSON(org.json.JSONObject json) {
//To change body of implemented methods use File | Settings | File Templates.
Log.d("Socket", "JSON");
}
});
}
});
}
echo "/gen/" >> .gitignore
Does this android socket.io client support socket.io namespacing? I've tried to use https://github.com/koush/android-websockets but it doesn't support namespacing. And as I see SocketIOClient class doesn't change too much. So is there any way to utilize namespaces like: "ws://localhost:3000/namespace1" or to set namespace on send?
Can you please add post support to the AsyncHttpServer?
Hi,
I am currently using the AndroidAsync library to developing Android app. I have a node.js socket.io server which has heartbeat timeout set at 280 secs, close timeout 120 secs, heartbeat interval 115 secs. However, every 60 secs my socket.io client will disconnect from the server. May I know if I should change any value in the library to accommodate this?
Thanks.
The HTTP Server example in README says this:
AsyncHttpServer mServer = new AsyncHttpServer(5000);
However, there is no constructor for AsyncHttpServer
that takes a port as constructor. The example should read:
AsyncHttpServer mServer = new AsyncHttpServer();
mServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("Hello!!!");
}
});
mServer.listen(5000);
Sometimes it happens that there is a proxy that brakes websocket so I added a timer, if the app can't connect within 10 seconds then it gives up and shows an error.
But how can I tell SocketIOClient to stop connecting once I called SocketIOClient.connect() ?
Hi, sorry but I have another exception, this time, it uploads up to 100% and then:
it happens every time I try. the file is only 100KB. any idea what it could be? I know the server works, because there are other implementations/clients that can upload images.
W/System.err: javax.net.ssl.SSLException: Fatal alert received bad_record_mac
W/System.err: at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:485)
W/System.err: at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
W/System.err: at com.koushikdutta.async.AsyncSSLSocketWrapper$1.onDataAvailable(AsyncSSLSocketWrapper.java:91)
W/System.err: at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:33)
W/System.err: at com.koushikdutta.async.BufferedDataEmitter.onDataAvailable(BufferedDataEmitter.java:61)
W/System.err: at com.koushikdutta.async.Util.emitAllData(Util.java:20)
W/System.err: at com.koushikdutta.async.AsyncNetworkSocket.onReadable(AsyncNetworkSocket.java:170)
W/System.err: at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:805)
W/System.err: at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:664)
W/System.err: at com.koushikdutta.async.AsyncServer.access$700(AsyncServer.java:34)
W/System.err: at com.koushikdutta.async.AsyncServer$14.run(AsyncServer.java:612)
Thanks!
Hi,
I am trying to make real-time multiplayer android game using your socket.io library. Everything works fine but data transfer seems to be too slow (about 0.7 sec delay). Can u please suggest something to make this connection a bit faster. On server side I am using node.js (express) with socket.io on nodejitsu.
try {
client = SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), "http://igrica.nodejitsu.com/", null).get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Packing in JSONObject, JSONArray and emmiting on server
final JSONObject obj = new JSONObject();
final JSONArray arr = new JSONArray();
try {
obj.put("velx", x);
obj.put("vely", y);
} catch (JSONException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
arr.put(0, obj);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Listening on response:
client.on("listening", new EventCallback(){
@Override
public void onEvent(JSONArray data, Acknowledge arg1) {
// TODO Auto-generated method stub
try {
//Log.e(null, data.getJSONObject(0).getString("velx"));
faceBody.setLinearVelocity(new Vector2(Float.parseFloat(data.getJSONObject(0).getString("velx"))*5,Float.parseFloat(data.getJSONObject(0).getString("vely"))*5));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
Sorry for bad format and thanks in advance:).
I am using futures that return a string as follows:
Future future = AsyncHttpClient.getDefaultInstance().getString(someUrl);
String result = future.get();
However, this throws an exception withing 20-30 seconds exactly, "java.util.concurrent.ExecutionException: java.util.concurrent.TimeoutException". I have even tried using the get(timeout, TimeUnit) method with the same result no matter the value for timeout. All the other requests to the same server that return more quickly all complete normally. At the very least, get() should block until specifically cancelled or the thread was interrupted and not throw a TimeoutException.
Hi,
I'm using the code below for socket communication. My socket gets connected and disconnected succesfully but when i do socket.emit(String name, JsonArray args), no callback events are triggered. I don't understand what i'm doing wrong. Please help me.
SocketIOClient.connect(AsyncHttpClient.getDefaultInstance(), req, new
ConnectCallback() {
@Override
public void onConnectCompleted(Exception ex, SocketIOClient client) {
if (ex != null) {
Log.i("SOCKET", "ex is not null!");
ex.printStackTrace();
return;
}
client.setErrorCallback(new ErrorCallback() {
@Override
public void onError(String arg0) {
Log.e("SOCKET", "Socket error: " + arg0);
}
});
client.setDisconnectCallback(new DisconnectCallback() {
@Override
public void onDisconnect(Exception arg0) {
Log.i("SOCKET", "Socket disconnected: " + arg0);
}
});
client.on("String", new EventCallback() {
@Override
public void onEvent(JSONArray arg0, Acknowledge arg1) {
Log.i("SOCKET", "Event call back");
}
});
client.setJSONCallback(new JSONCallback() {
@Override
public void onJSON(JSONObject json, Acknowledge acknowledge) {
Log.i("SOCKET", "Json call back");
}
});
}
});
Hi,
I am looking for acknowledgment function for the socket io client, there are some socket event callback in my project need to get acknowledgement. Is this available?
Thanks.
First, I'd like to thank you for this amazing lib, it's impressive! I'm using it to develop a WebSocket and Socket.io plugin for Game Closure.
I tried to use setClosedCallback and setEndCallback to handle onclose event, but these callbacks seem to be never called.
AsyncHttpClient.getDefaultInstance().websocket(url, protocol, new WebSocketConnectCallback() {
@Override
public void onCompleted(Exception ex, WebSocket websocket) {
// onopen
websocket.setStringCallback(new StringCallback() {
public void onStringAvailable(String data) {
// onmessage
}
});
websocket.setClosedCallback(new CompletedCallback() {
public void onCompleted(Exception ex) {
// onclose
}
});
websocket.setEndCallback(new CompletedCallback() {
public void onCompleted(Exception ex) {
// ???
}
});
}
});
I have some questions about that:
In case the content length is bigger then 8192 b ~ (8K)
The post body content is not complete
So if i am sending a "big" json string , I am getting only part of the string
This is a blocking , show stopper issue
is there any way to add support for SNI?
right now, AsyncSSLSocketWrapper.handleResult is checking the host with a certificate. but it doesn't work if the server is using SNI.
TIA!!
The websocket client implementation sends the generated UUID as a string instead of base64 encoded
RFC 6455 - 4.1. Client Requirements
socket io doesn't re-establish the connection to the server when the transport is interrupted.
it should reconnect automatically unless the user explicitly disconnects it. Please refer https://github.com/Gottox/socket.io-java-client#socketio-client-for-java . they have done it nicely.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.