.NET WebSocket Client Control

2.3k views Asked by At

I am trying to write a very simple WebSocket client with VB.NET but couldn't find a ready-to-use webSocket control.

There is one control that does exactly what I am looking for: IP*Works! WS from nSoftware, but unfortunately they charge a fortune for it.

Here is a screenshot of the demo app they provide:

enter image description here

Question: Does anyone know of a similar free/low-budget .NET control to do the same ?

Note: I have tested this demo app with VB.NET and it works flawlessly connecting to: ws://echo.websocket.org

edit: Also, I would remain interested in hearing from XOJO/RealBasic, Xamarin and LiveCode users for a similar solution that actually works with this server -> ws://echo.websocket.org

2

There are 2 answers

1
Jack M. On BEST ANSWER

Ok, after a few days working on this I figured it out:

  • With VB.NET there are a lot of libraries and information available throughout and there are some ready to use controls available. Nsoftware has a very good one but is too expensive. The free controls are not that good and most of them outdated (old specs). The best thing to do is write the specs manually but the existing demos, documentation and libraries are extremely helpful.

  • With XOJO there is no such thing like a ready to use control so I had to use the TCP Socket control and implement the specification manually. It is working okay now thanks to the community since it's help articles are rubbish.

  • I did not took much time doing tests in LiveCode but I believe the problem is the same. Since there is no ready to use controls available, at least as far as I know, I'd probably had to write the specification manually in Live Code like I did in Xojo.

Basically, although not easy, it is possible in any programming language I would guess.

6
Mark On

Your own tests with RealStudio and my tests with LiveCode don't work (so far) because with every request you need to send headers. The headers that the client needs to send to shake hands with the server are

    GET /chat HTTP/1.1
    Host: server.example.com
    Upgrade: websocket
    Connection: Upgrade
    Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
    Origin: http://example.com
    Sec-WebSocket-Protocol: chat, superchat
    Sec-WebSocket-Version: 13

Probably, you can set the httpHeaders in LiveCode and use simple put/get URL commands to communicate with the server. I will try this and will edit my answer later.

Another LiveCode solution is to set the html of a revBrowser control and call the JavaScript function from a LiveCode script using the revBrowserExecuteScript() function.