osc.js-examples icon indicating copy to clipboard operation
osc.js-examples copied to clipboard

Can a HTTP Server and WebSocket Server share the same Port

Open konvasil opened this issue 1 year ago • 2 comments

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.

konvasil avatar Apr 23 '24 08:04 konvasil

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.

colinbdclark avatar Apr 23 '24 22:04 colinbdclark

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

konvasil avatar Apr 23 '24 23:04 konvasil