0

I am trying to connect to a webSocket server on port 2998 using the c# package websocket-sharp.

On the client side I am using the following code (written in c#):

WebSocket webSocket = new WebSocket("ws://localhost:2998");
webSocket.Connect();
webSocket.Send("test");

On the server side i am using node.js running the following code (written in typescript):

import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({
    port: 2998,
});

wss.on("connection", (ws) => {
    console.log("connected")
    ws.on('error', console.error);

    ws.on('message', function message(data) {
        console.log('received: %s', data);
    });

    ws.send('something');
})

I expected to see connected and test logged in the terminal on the server side, but nothing is being logged. If you can provide me with a solution or help of any kind it would be greatly appreciated.

PentaMine
  • 31
  • 3

1 Answers1

0

Turns out the package I was using does not work, if you are trying to use websocket-sharp in Unity i would recommend switching to NativeWebSocket it does the same thing, but it actually works.

PentaMine
  • 31
  • 3