简体   繁体   中英

SocketIO: Web socket error upon sending bigger payloads

I'm trying to send a payload of size ~10MB to a server. Every time I try to do it, the socket io library crashes with the following crashlogs. I'm not really sure why is it crashes and how can I fix it. In the future, we are planning to move the data transferal tasks to HTTP protocol but for now we have to work with sockets.

Any ideas how can I fix it or circumvent this issue?

2019-06-12 15:39:44.927 24039-24055/com.hulu.mdm.agent D/com.hulu.mdm.internal.socketLogging.AndroidLoggingHandler: io.socket.client.Manager
2019-06-12 15:39:44.924 24039-24141/com.hulu.mdm.agent W/System.err: io.socket.engineio.client.EngineIOException: websocket error
2019-06-12 15:39:44.928 24039-24141/com.hulu.mdm.agent W/System.err:     at io.socket.engineio.client.Transport.onError(Transport.java:63)
2019-06-12 15:39:44.929 24039-24055/com.hulu.mdm.agent I/_MdmSocketImpl: Socket-Error occured!
2019-06-12 15:39:44.930 24039-24141/com.hulu.mdm.agent W/System.err:     at io.socket.engineio.client.transports.WebSocket.access$400(WebSocket.java:24)
2019-06-12 15:39:44.933 24039-24141/com.hulu.mdm.agent W/System.err:     at io.socket.engineio.client.transports.WebSocket$1$5.run(WebSocket.java:107)
2019-06-12 15:39:44.933 24039-24141/com.hulu.mdm.agent W/System.err:     at io.socket.thread.EventThread$2.run(EventThread.java:80)
2019-06-12 15:39:44.934 24039-24141/com.hulu.mdm.agent W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
2019-06-12 15:39:44.934 24039-24141/com.hulu.mdm.agent W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
2019-06-12 15:39:44.934 24039-24141/com.hulu.mdm.agent W/System.err:     at java.lang.Thread.run(Thread.java:764)
2019-06-12 15:39:44.935 24039-24141/com.hulu.mdm.agent W/System.err: Caused by: java.net.SocketException: Connection reset
2019-06-12 15:39:44.935 24039-24141/com.hulu.mdm.agent W/System.err:     at java.net.SocketInputStream.read(SocketInputStream.java:209)
2019-06-12 15:39:44.936 24039-24141/com.hulu.mdm.agent W/System.err:     at java.net.SocketInputStream.read(SocketInputStream.java:139)
2019-06-12 15:39:44.936 24039-24141/com.hulu.mdm.agent W/System.err:     at okio.Okio$2.read(Okio.java:139)
2019-06-12 15:39:44.936 24039-24141/com.hulu.mdm.agent W/System.err:     at okio.AsyncTimeout$2.read(AsyncTimeout.java:237)
2019-06-12 15:39:44.936 24039-24141/com.hulu.mdm.agent W/System.err:     at okio.RealBufferedSource.request(RealBufferedSource.java:67)
2019-06-12 15:39:44.937 24039-24141/com.hulu.mdm.agent W/System.err:     at okio.RealBufferedSource.require(RealBufferedSource.java:60)
2019-06-12 15:39:44.937 24039-24141/com.hulu.mdm.agent W/System.err:     at okio.RealBufferedSource.readByte(RealBufferedSource.java:73)
2019-06-12 15:39:44.937 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.internal.ws.WebSocketReader.readHeader(WebSocketReader.java:113)
2019-06-12 15:39:44.937 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.internal.ws.WebSocketReader.processNextFrame(WebSocketReader.java:97)
2019-06-12 15:39:44.938 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.internal.ws.RealWebSocket.loopReader(RealWebSocket.java:262)
2019-06-12 15:39:44.938 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:201)
2019-06-12 15:39:44.938 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
2019-06-12 15:39:44.939 24039-24141/com.hulu.mdm.agent W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
2019-06-12 15:39:44.939 24039-24141/com.hulu.mdm.agent W/System.err:    ... 3 more
2019-06-12 15:39:44.953 24039-24055/com.hulu.mdm.agent I/_MdmSocketImpl: [io.socket.engineio.client.EngineIOException: websocket error]

As per the crash-log, I can see the socket is being reset by server. Do your server support writing in chunks? The suggested way to copy a stream in Java is this:

while ((count = in.read(buffer)) > 0)
{
  out.write(buffer, 0, count);
}

Please check on your server side, they might be getting OutOfMemoryError .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM