简体   繁体   中英

Web-socket worked for small files of ~8KB. But for ~50KB file, my connection disconnects

We try below code on the server-side. I am facing some issue when sending image more the 731276 bytes but able to upload 23969 bytes using WebSocket.

// websocket and http servers
var webSocketServer = require('websocket').server;
var http = require('http');

// list of currently connected clients (users)
var clients = [];

function htmlEntities(str) {
    return str;
}

var server = http.createServer(function(request, response) {

});
server.listen(webSocketsServerPort, function() {});
var wsServer = new webSocketServer({
    httpServer: server
});

// tries to connect to the WebSocket server
wsServer.on('request', function(request) {

    var connection = request.accept(null, request.origin);

    console.log((new Date()) + ' Connection accepted.');

    // user sent some message
    connection.on('message', function(message) {

        if (message.type === 'binary') { // accept only binary

          // broadcast message to all connected clients

            for (var i = 0; i < clients.length; i++) {
                clients[i].send(message.binaryData);
                //clients[i].send(json);
            }
        }
    });
});

How to send big image one client to multiple clients?

Please try this one. This working on my side.

//[MB KB Bytes] 10 MB = 10 * 1024 * 1024

var wsServer = new webSocketServer({
            httpServer: server,
            maxReceivedFrameSize: 10 * 1024 * 1024,
            maxReceivedMessageSize: 10 * 1024 * 1024,
            autoAcceptConnections: false
        });

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