通常在通过socket.io发送图像数据时断开连接

时间:2018-07-06 10:03:19

标签: react-native socket.io

我正在使用socket.io从反应本地移动设备向服务器传输经过base64编码的图像。但是断开连接经常发生(70%的故障)。

发送文本时不会发生这种情况。这是我的简化代码:

服务器端:

const app = require('http').createServer();
app.listen(3005);
const server = require('socket.io')(app);
server.on('connection', client => {
    client.on('data', data => console.log(data));
});

客户端:

import io from "socket.io-client";
const socket = io("ws://the_lan_ip_of_server:3005");
socket.on("connect", () => console.log("Connect", socket.id));
socket.on("disconnect", () => console.log("Disconnect));

// I just copy the file obtained from console.
let file = {
    height: 1802,
    width: 1080,
    type: null,
    fileName: 'Capture+_2018-07-06-12-05-12.png',
    fileSize: 2659778,
    path: '/storage/emulated/0/Capture+/Capture+_2018-07-06-12-05-12.png',
    data: 'the image data',
    uri: 'content://media/external/images/media/483',
    isVertical: true,
    originalRotation: 0
};
let data = { type: "File", "action": "Create", base64: file.data };
console.log(data.type, data.action, socket.id);
socket.emit("data", data);

没有从服务器端获得控制台日志,但是对于ClientSide日志是

07-06 17:49:09.400: I/ReactNativeJS(22397): 'Connect', 'JnghiSpOSpufU85tAAAF'
07-06 17:49:09.421: I/ReactNativeJS(22397): 'Submit', 'File', 'Create', 'JnghiSpOSpufU85tAAAF'
07-06 17:49:14.445: I/ReactNativeJS(22397): Disconnect
07-06 17:49:18.363: I/ReactNativeJS(22397): 'Connect', 'CbqHvecSXdmG811KAAAG'

有人可以给我一些想法解决这个问题吗?

0 个答案:

没有答案