colinbdclark / osc.js-examples

Sample code illustrating how to use osc.js in a variety of scenarios.
104 stars 28 forks source link

Can a HTTP Server and WebSocket Server share the same Port #25

Open konvasil opened 2 months ago

konvasil commented 2 months ago

Is this something that can be done, and increase efficiency or better to have to different ports for each? I am asking this here because when I am pressing my button that is bind with osc message sent function it sends the message after 3 clicks approximatelly, so I am wondering if this is because the websocket server uses a different port number.

colinbdclark commented 2 months ago

I think it's typical that they do, yes. That's how the osc.js browser example works. I'm not sure, though, that the port(s) used is the cause of the issue you're facing. But it sounds like some strategic logging and/or use of a debugger will help track it down.

konvasil commented 2 months ago

Interesting, thanks for the link. I tried to modify the server part according to your example, but now it throws this error:

A Web Socket connection has been established!
/Users/k.vasilakos/Dev/ltt/node_modules/osc/src/osc.js:101
            throw new Error("Can't wrap a non-array-like object as Uint8Array. Object was: " +
                  ^

Error: Can't wrap a non-array-like object as Uint8Array. Object was: "�l�-�y"
    at osc.byteArray (/Users/k.vasilakos/Dev/ltt/node_modules/osc/src/osc.js:101:19)
    at p.decodeOSC (/Users/k.vasilakos/Dev/ltt/node_modules/osc/src/osc-transports.js:79:20)
    at osc.WebSocketPort.emit (node:events:519:28)
    at socket.onmessage (/Users/k.vasilakos/Dev/ltt/node_modules/osc/src/platforms/osc-websocket-client.js:58:18)
    at callListener (/Users/k.vasilakos/Dev/ltt/node_modules/ws/lib/event-target.js:290:14)
    at WebSocket.onMessage (/Users/k.vasilakos/Dev/ltt/node_modules/ws/lib/event-target.js:209:9)
    at WebSocket.emit (node:events:519:28)
    at Receiver.receiverOnMessage (/Users/k.vasilakos/Dev/ltt/node_modules/ws/lib/websocket.js:1209:20)
    at Receiver.emit (node:events:519:28)
    at /Users/k.vasilakos/Dev/ltt/node_modules/ws/lib/receiver.js:608:16

Node.js v21.7.3