dcsimg
Results 1 to 9 of 9

Thread: WEBSOCKET desktop client

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110

    WEBSOCKET desktop client

    I would like to create a desktop application in VB.NET that uses WebSocket to communicate with websocket enabled wep page.

    Can someone please point me to right direction how to create desktop variant of this websocket ECHO test.
    http://www.websocket.org/echo.html

    Thanks.
    Ermin Gutenberger

    VB.NET 2010

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: WEBSOCKET desktop client

    Websocket protocols are only available in .Net Framework 4.5 (and possibly even then only with W8) so at the very least you're going to need to update your VS to 2013. The Websockets package is not included by default so you would also have to install it (using NuGet, for example). If you're in a position to do that, then we can consider the question.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110

    Re: WEBSOCKET desktop client

    Thank you for your response. Sorry for my outdated signature.

    I have VS2013 and .NET 4.5.1 installed. As of 4.5 .NET suppose to support websockets. I have no problems adding

    Imports System.Net.WebSockets.ClientWebSocket

    to my projects. So I believe I have everything I need.

    Thank you.
    Ermin Gutenberger

    VB.NET 2010

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: WEBSOCKET desktop client

    Sadly the ability to import the Socket and indeed to code for it does not necessarily mean that it is supported on your machine. I've just done a quick test and it does look like you need W8. If you have then you can proceed but I'm afraid I don't so this is as far as I can go with certainty.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110

    Re: WEBSOCKET desktop client

    I also tried Alchemy Websockets. I got onConnect event fired, also "client.connected" returns true but all other events does not fire.

    Any thoughts?

    My VB code:

    Code:
    Imports Alchemy
    Imports Alchemy.Classes
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim aClient = New WebSocketClient("ws://echo.websocket.org:80/")
            With aClient
                .OnReceive = AddressOf onDataReceive
                .OnConnect = AddressOf OnUserConnect
                .OnConnected = AddressOf onUserConnected
                .OnSend = AddressOf onDataSend
                .OnDisconnect = AddressOf onUserDisconnect
            End With
    
    
            aClient.Connect()
            MsgBox(aClient.Connected)
            If aClient.Connected = True Then
                aClient.Send("Hey!")
                aClient.Disconnect()
            End If
            End
        End Sub
    
    
        Private Sub OnUserConnect(context As Alchemy.Classes.UserContext)
            MsgBox("Connecting")
        End Sub
    
    
        Private Sub OnUserConnected(context As Alchemy.Classes.UserContext)
            MsgBox("Connected")
        End Sub
    
        Private Sub onDataSend(context As Alchemy.Classes.UserContext)
            MsgBox("Send")
        End Sub
    
    
        Private Sub onUserDisconnect(context As Alchemy.Classes.UserContext)
            MsgBox("Disconnect")
        End Sub
    
        Private Sub onDataReceive(context As Alchemy.Classes.UserContext)
            MsgBox("Server response : " & context.DataFrame.ToString())
        End Sub
    End Class
    Ermin Gutenberger

    VB.NET 2010

  6. #6
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: WEBSOCKET desktop client

    Had a long and frustrating fiddle with this and got very little sense out of it, I'm afraid. Part of the problem is that you're using message boxes which interrupt the flow of the program and are potentially cross threading. But having got rid of those and replaced them with a thread safe return to a textbox only succeeded in getting me as far as send. Nothing ever suggested that data was returned or if it was that it fired the receive event. Then there was the further problem that the disconnect returned a null reference exception and I can't for the life of me see why. So, fair to say that it's not looking like the road to success at the moment. I may give it another try as a Console app but I'm not hopeful.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 1999
    Location
    SLOVENIA, Europe
    Posts
    110

    Re: WEBSOCKET desktop client

    Thank you for your effort on this. Did you try it on Windows 8? I tried it on Win7 sp1 and had same result as you except exception at disconnect.

    It would be nice to have working desktop client. I'm not ready to abandon this idea just yet. But as I dig deeper into WEBSOCKETS more I realize that even if I somehow manage to create desktop client, there is no way that I can write application that will work from Win XP onwards.
    Ermin Gutenberger

    VB.NET 2010

  8. #8
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,242

    Re: WEBSOCKET desktop client

    No, I'm sticking to W7 (possibly for life)! I don't see anywhere in Alchemy's bumpf that it says it shouldn't work in W7 and it is compiled on .Net 4, but there you go. I did try a console version both in VB and C# but that did some very weird things that meant it wouldn't compile.
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  9. #9
    Addicted Member
    Join Date
    May 2011
    Posts
    230

    Re: WEBSOCKET desktop client

    Quote Originally Posted by ermingut View Post
    I also tried Alchemy Websockets. I got onConnect event fired, also "client.connected" returns true but all other events does not fire.

    Any thoughts?

    My VB code:

    Code:
    Imports Alchemy
    ...
            With aClient
                .OnReceive = AddressOf onDataReceive
                .OnConnect = AddressOf OnUserConnect
                .OnConnected = AddressOf onUserConnected
                .OnSend = AddressOf onDataSend
                .OnDisconnect = AddressOf onUserDisconnect
            End With
    
    
        Private Sub onDataSend(context As Alchemy.Classes.UserContext)
            MsgBox("Send")
        End Sub
    
    
        Private Sub onUserDisconnect(context As Alchemy.Classes.UserContext)
            MsgBox("Disconnect")
        End Sub
    
        Private Sub onDataReceive(context As Alchemy.Classes.UserContext)
            MsgBox("Server response : " & context.DataFrame.ToString())
        End Sub
    End Class
    probably dead thread, but I was looking for this kind of solution and (thanks btw, really helped me)
    and I notice in your code was error in case-sensitive function name.

    Vb6 (Classic) was case-insensitive,
    Vb.Net is by IDE case-insensitive, but compiler (.NET) is case-SENSITIVE
    (wich make thing very confusing)

    Never forget that the team that forged Vb.Net wasn't the MVS Vb6 Team but the MVS VC Team.

    thanks for the code.
    Last edited by VbNetMatrix; Oct 14th, 2017 at 11:52 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width