Giter VIP home page Giter VIP logo

Comments (4)

tippexs avatar tippexs commented on August 30, 2024

Hi @ruspaul013 Thanks for reaching out and sorry for the long delay in my response. We had lately another Node related issue and this one felt of the radar. Will pick it up again.

You can have a look at the test application posted here https://github.com/nginx/unit/blob/master/test/node/loader/es_modules_websocket/app.mjs

This test makes use of the loader you are using as well. The loader configuration can be found here
https://github.com/nginx/unit/blob/master/test/unit/applications/lang/node.py

Copied from our tests, can you give this a try?

import http from "http"
import websocket from "websocket"

let server = http.createServer(function() {});
let webSocketServer = websocket.server;

server.listen(8080, function() {});

var wsServer = new webSocketServer({
    maxReceivedMessageSize: 0x1000000000,
    maxReceivedFrameSize: 0x1000000000,
    fragmentOutgoingMessages: false,
    fragmentationThreshold: 0x1000000000,
    httpServer: server,
});

wsServer.on('request', function(request) {
    var connection = request.accept(null);

    connection.on('message', function(message) {
        if (message.type === 'utf8') {
            connection.send(message.utf8Data);
        } else if (message.type === 'binary') {
            connection.send(message.binaryData);
        }

  });

  connection.on('close', function(r) {});
});

However as you can see we are using different imports. Can you try to use

import http from "http"
import websocket from "websocket"

as well? We will have to play around with ws to see why and where we have issues with that.

from unit.

andrey-zelenkov avatar andrey-zelenkov commented on August 30, 2024

Adding some info to the @tippexs reply. We do support only websockets for now. So you if you rewrite you demo app to something like:

server = require('http').createServer(function() {});
webSocketServer = require('websocket').server;

server.listen(3010, function() {});

var wsServer = new webSocketServer({
    maxReceivedMessageSize: 0x1000000000,
    maxReceivedFrameSize: 0x1000000000,
    fragmentOutgoingMessages: false,
    fragmentationThreshold: 0x1000000000,
    httpServer: server,
})

var clients = [];


wsServer.on('request', request => {
    var connection = request.accept(null);
    console.log('New client connected!');

    clients.push(connection);

    connection.send('connection established');
    connection.on('message', data => {
        clients.forEach(client => {
            console.log(`distributing message: ${data}`)

            if (data.type === 'utf8') {
                client.send(data.utf8Data);
            } else if (data.type === 'binary') {
                client.send(data.binaryData);
            }

        })
    })
    connection.onerror = function () {
        console.log('websocket error')
    }

    connection.on('close', () => console.log('Client has disconnected!'));
})

then it should work with our Node module.

from unit.

tippexs avatar tippexs commented on August 30, 2024

@andrey-zelenkov thanks for adding this. I think we can be more explicit about what websockets and ws is and what we support. A setense should be enough I guess.

from unit.

ruspaul013 avatar ruspaul013 commented on August 30, 2024

Hello @tippexs @andrey-zelenkov !

I know that websocket is working ( I made a demo app using it ) but it's complicated to change from ws to websocket for what I need. I am interested if do you plan any support for ws in the future.

from unit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.