4

I was using Alchemy websockets for both my client and server but ran into a problem with corrupted/dropped messsages. So I'm trying out another server side implementation. I implemented the server using Fleck, and when I send messages using javascript, the server receives all the messages, solving my previous problem.

However, I need to be able to send messages to the websocket server from a C# client also. Since Fleck does not have a client side implementation in C#, I thought I'd stick with Alchemy. I left the client-side code unchanged so I thought it should just connect to the server as before, however, no messages are being received (though they are being sent according to the debugger).

Here is my server side implementation (Fleck):

private void OnStartWebSocketServer()
        {
            var server = new WebSocketServer("ws://localhost:11005");
            server.Start(socket =>
            {
                socket.OnOpen = () => Console.WriteLine("Open!");
                socket.OnClose = () => Console.WriteLine("Close!");
                socket.OnMessage = message => OnReceive(message);
            });
        }


    private static void OnReceive(String message)
    {
        UpdateUserLocation(message);
    }

Here is my client side implementation (Alchemy):

class WSclient
{

    WebSocketClient aClient;

    public WSclient(String host, String port)
    {


        aClient = new WebSocketClient("ws://" + host + ":" + 11005 + "/chat")
        {
            OnReceive = OnReceive,
            OnSend = OnSend,
            OnConnect = OnConnected,
            OnConnected = OnConnect,
            OnDisconnect = OnDisconnect
        };

        aClient.Connect();
    }

    ...

    public void Send(String data)
    {
        aClient.Send(data);
    }

I thought it might have something to do with the fact that the Alchemy client requires a channel at the end of the connection string '/chat'. However leaving it blank, or just the '/' gives an error.

Community
  • 1
  • 1
Matt
  • 3,820
  • 16
  • 50
  • 73

0 Answers0