1

I am trying to connect to a C# TCP server using HTML5 from the example in http://www.tutorialspoint.com/html5/html5_websocket.htm

<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function WebSocketTest()
{
    if ("WebSocket" in window)
    {
     alert("WebSocket is supported by your Browser!");
     // Let us open a web socket
     var ws = new WebSocket("ws://localhost:9998/echo");
     ws.onopen = function()
     {
        // Web Socket is connected, send data using send()
        ws.send("Message to send");
        alert("Message is sent...");
     };
     ws.onmessage = function (evt) 
     { 
        var received_msg = evt.data;
        alert("Message is received...");
     };
     ws.onclose = function()
     { 
        // websocket is closed.
        alert("Connection is closed..."); 
     };
    }
    else
    {
     // The browser doesn't support WebSocket
     alert("WebSocket NOT supported by your Browser!");
    }
}
</script>
</head>
<body>
<div id="sse">
<a href="javascript:WebSocketTest()">Run WebSocket</a>
</div>
</body>
</html>

The TCP server runs on the local machine on port 4530. So I changed

var ws = new WebSocket("ws://localhost:9998/echo"); 

to

var ws = new WebSocket("ws://localhost:4530");

When I run the page, I get the message WebSocket is supported by your Browser! and it hangs there. Any help?

5
  • 2
    Does your server support the correct WebSocket protocol? It may depend on the browser that you use Commented Nov 20, 2012 at 6:45
  • You mean the tcp server should support Websocket as well? As far as the browser is concerned, isn't the message WebSocket is supported by your Browser! sufficient? Commented Nov 20, 2012 at 6:50
  • 1
    Websockets are using a special protocol on top of TCP, including some extra connection handshaking. It's not like normal sockets that you can just connect and start communicating. Commented Nov 20, 2012 at 6:52
  • @Mika, please take a look at the link in my previous comment (the word browser). There you will see that different browsers use different websocket protocols. Your test is only checking if the browser does support WebSockets at all but does not say anything about the protocol version that is used Commented Nov 20, 2012 at 6:52
  • Ok. Thanks for clearing some of my misconceptions. Commented Nov 20, 2012 at 7:28

1 Answer 1

1

Mika, have a look at http://xsockets.net , its a easy to get started real-time framework for dotnet (c#) , is canbe found on Nuget. Just hit Install-Package XSockets in the PM Console.

The framework handels 6455 specifications aswell has it does do the "old" Hybi00 protocl (draft).

It has a jQuery similar clientside JavaScript library and the server-side API reminds of MVC.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.