Skip to content

Websocket connection not established #448

@Ridlah

Description

@Ridlah

Hi

I am trying to establish basic websocket connection and I got the following error:
It looks like I am missing something essential, but dont know what. Thank you for any help.

AS Client:
16. 4. 2018 13:21:22|Debug|WebSocket.sendHttpRequest:0|A request to the server:
GET / HTTP/1.1
User-Agent: websocket-sharp/1.0
Host: 127.0.0.1:9556
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: o1qYAebHa7NAprHij9XAyA==
Sec-WebSocket-Version: 13
16. 4. 2018 13:21:22|Debug|WebSocket.sendHttpRequest:0|A response to this reques
t:
HTTP/1.1 501 Not Implemented
Server: websocket-sharp/1.0
Connection: close
16. 4. 2018 13:21:22|Error|WebSocket.doHandshake:0|Not a WebSocket connection re
sponse.
16. 4. 2018 13:21:22|Trace|WebSocket.close:0|Begin closing the connection.
16. 4. 2018 13:21:22|Debug|WebSocket.closeHandshake:0|Was clean?: False
sent: False
received: True
16. 4. 2018 13:21:22|Trace|WebSocket.close:0|End closing the connection.
16. 4. 2018 13:21:22|Error|WebSocket.Send:0|The WebSocket connection has already
been closed.

As Server
16. 4. 2018 13:21:22|Error|WebSocketServiceManager.InternalTryGetServiceHost:0|A
WebSocket service with the specified path isn't found:
path: /
16. 4. 2018 13:21:22|Debug|WebSocket.sendHttpResponse:0|A response to this reque
st:
HTTP/1.1 501 Not Implemented
Server: websocket-sharp/1.0
Connection: close

Server Code

static void Main(string[] args)
{
    var websocketServer = new WebSocketServer(System.Net.IPAddress.Loopback, 9556);
    websocketServer.AddWebSocketService<BasicWebsocketBehaviour>("/BasicWebsocketBehaviour");
    websocketServer.Start();
    Console.ReadLine();
    websocketServer.Stop();
}

BasicWebsocketBehaviour is the same folder as Main Program Class

class BasicWebsocketBehaviour : WebSocketBehavior
{
    protected override void OnMessage(MessageEventArgs e)
        {
            base.OnMessage(e);
            Console.WriteLine("msg: {0}", e.Data);
        }
}

Client code

static void Main(string[] args)
{
    using (var ws = new WebSocket("ws://127.0.0.1:9556"))
    {
        ws.OnMessage += (sender, e) => Console.WriteLine("MSG: {0}", e.Data);

        ws.Connect();
        ws.Send("Hello from the Client!");

        Console.ReadLine();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions