Results 1 to 19 of 19

Thread: [VB6] Visual Basic 6 Client Websocket Control 1.4.1 BETA

  1. #1

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    [VB6] Visual Basic 6 Client Websocket Control 1.4.1 BETA

    Greetings Friends,

    I present to you the first free client Websocket control made in Visual Basic 6 (with source code) that can handle both secure (ssl/ssh) and normal websocket server connections!

    Name:  ss3.jpg
Views: 29
Size:  49.3 KB

    I have personally had to abandon 3 large personal projects of my own because i needed websocket functionality with SSL and couldn't find anything on the internet to fulfill that need (free or open source). I started a couple times to try to code one of my own but the extreme complexity of implementing SSL and lack of time always hindered my progress and I usually gave up an moved on to something else. (if you check the SSL code you will know what i mean by complex).

    But then alas, one day I stumbled upon wqweto's VBAsyncSocket project and hope once again glimmered in my eyes. Here was a project with full SSL/TLS implementation that worked seamlessly under the hood and supported IPV6 to boot. I then came across joshyfrancis's post regarding a websocket server, which led me to Youran's online example code. All of which helped me in achieving my goal of creating a client websocket control in VB6. This project wouldn't have been possible without those people's contributions. Hopefully, you will find this useful and beneficial to your websocket related projects.

    Note, this websocket doesnt support application layer protocols, and full HTTP header handling, mainly because it doesn't have the full power of a web browser behind it like most websockets. As such it handles only the most simplest of http redirects where location: in the header defines the new URL. Amazon Cloudfront redirects for example are not handled. You are also responsible for any data formatting such as JSON, XML etc.. This control only deals with the actual websocket protocol layer.

    Some Uses for a Websocket control are:

    1) Connect to and control OBS Studio with the OBS-WebSocket plugin.
    2) Connect to cryptocurrency websites and retrieve pricing and/or actually make trades
    3) Connect to sports sites and get sports ticker information
    4) Easily implement multimedia chat, text chat, and shared drawing
    5) Similar to crypto, connect to Stock sites and get financial information and tickers
    6) Connect to Social Media Sites and get real-time timeline updates
    7) Connect to Twitch IRC chat and implement a chat bot

    Please post any bugs or questions related to the websocket control below and I will try to fix them as much as possible. If you make any useful additions, please share them so they can be added into the main source code.

    Please direct any questions regarding the SSL code to wqweto as I don't know crap about SSL.

    best regards,
    vbLewis


    Version 1.4.1 BETA - 9/15/2021
    1) fixed several copy paste bugs in the send function, if you previously downloaded 1.4 you will want to update it with this new version
    2) added a reconnect function that reconnects using the current state of the websocket

    Version 1.4 BETA - 9/15/2021
    ----------------------------------------------------------------------------
    1) Fixed a bug with sending ready made close, ping,and pong frames (leftover old code bug) .
    2) Related to #1 - fixed a bug with answering server pings.
    3) Handling of server close messages with an error code and description included is now complete and working properly.
    4) fixed the piesocket disconnect issue and improved the piesocket demo.(also related to #1)
    5) changed the fragmented frames strategy from a single buffer, to a list of buffers.
    6) finished all the http code error messages. oops
    7) Add a OnPong() event and a Ping() method. This allows for user to send pings to the server and recieve the pong answer.
    8) Various other small bug fixes and errors corrected


    UPDATE 1.3 - 9/1/2021
    1) Encoding data was flawed, it is now fixed and per standard rfc6455
    2) Added checking for most invalid characters in the URL (aka URI) passed to the Connect function.
    3) an html help file page has been added explaining parameters, arguments, methods, events, properties, and enums, it is in the main directory as HELP.html.
    4) changed a few error codes and added some new ones to reflect industry standard accepted error codes, even though they are not all in the websocket standard rfc6455.
    5) almost all possible http error codes are now handled and identified. (huge function)
    6) added a onProgress event. This event could be used to implement a progress bar or status on large sends. It will only activate on data larger than 4kb.
    7) Added a isBusy property. Check this read-only property to see if the websocket is busy. if it is TRUE the websocket is in the process of sending or recieving data.

    8) Added support for compression, and thus another wqweto class (cZipArchive) which handles deflate/inflate. use the UseCompression property before connecting to activate.
    The server must support compression in order to use it. After connecting you can enable/disable compression as needed, for example: to send a binary message.
    If you plan on using compression at all, you MUST set useCompression to True BEFORE connecting so that the proper Extension header is negotiated. Otherwise
    the websocket will not compress the data if the server has not accepted the extension, even if useCompression is True.

    9) Added support for extensions in the Connect() function, these work the same as sub-protocols, but reminder that the websocket handles deflate compression internally. see 8)
    You could implement your own compression deflate algo by using byte arrays and sending in binary mode. Fill in the ProtocolExtensions parameter with the desired extension(s).
    These are in the same format as the SubProtocols parameter (CSV). Check Extensions property after connecting to see if the server accepted your extension.
    Currently only 2 extensions are registered with IANA - BBF USP protocol (for IOT devices) and permessage-deflate but more are in the works.

    10) Cleaned up the websocket interface for some private internal functions that were exposed.
    11) Fixed several Off-By-One errors in packet splitting functions, hopefully they are all fixed. Working with arrays is error-prone and complex going from C to VB and back.
    As usual if you find any errors please report to the vbforums post.

    12) Add a BTC ticker example using coinbase pro

    Known Issues:
    1) Proxies are not supported, will probably add support in a future update.
    2) There are several features (such as compression) that have not been tested because I cant find a server to test them with, but in theory they should work so long as the code is correct.


    See CHANGELOG.txt for older updates.
    Attached Files Attached Files
    Last edited by vbLewis; Sep 15th, 2021 at 11:01 AM. Reason: Websocket Code And Feature Update

  2. #2
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    286

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Very good work.
    I am trying to connect to the next server, but it gives me problems, it disconnects from the server.

    It works well
    Code:
    wss://echo.websocket.org
    this not

    apikey is real apikey.
    http://piesocket.com
    Code:
    wss://us-nyc-101.piesocket.com/v3/1?api_key=apikey&notify_self
    Good work, keep it up

  3. #3

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    its supposed to handle query params but the server might be returning something in the header, ill have to do more testing.. I forgot to mention that redirects to amazons cloudfront servers arent handled.

    Edit:
    Dear Yokesee, it appears that server is no longer online or its DNS isn't working, error is "No such Host is Known"

    I have tried there demo sever and it connects, however it doesnt support chat, superchat, or echo protocols which basically means
    the piesocket servers require all messages to be formatted in json encoding.
    Last edited by vbLewis; Aug 1st, 2021 at 03:57 AM.

  4. #4
    Frenzied Member
    Join Date
    Jan 2020
    Posts
    1,563

    Re: [VB6] Visual Basic 6 Client Websocket Control

    it's nice,how to change for serve mode?
    use ie to connect wss://127.0.0.1:443?

  5. #5

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    you should be able to just put wss://127.0.0.1:443 in the text1 to connect to a local server, i havent tried that myself. Also this is a "Client" only control, doesnt do server mode.

  6. #6
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    525

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by vbLewis View Post
    Greetings Friends,

    I present to you the first free client Websocket control made in Visual Basic 6 (with source code) that can handle both secure (ssl/ssh) and normal websocket server connections!

    Attachment 181963

    I have personally had to abandon 3 large personal projects of my own because i needed websocket functionality with SSL and couldn't find anything on the internet to fulfill that need. I started a couple times to try to code one of my own but the extreme complexity of implementing SSL and lack of time always hindered my progress and I usually gave up an moved on to something else. (if you check the SSL code you will know what i mean by complex)

    But then alas, one day I stumbled upon wqweto's VBAsyncSocket project and hope once again glimmered in my eyes. Here was a project with full SSL/TLS implementation that worked seamlessly under the hood and supported IPV6 to boot. I then came across joshyfrancis's post regarding a websocket server, which led me to Youran's online example code. All of which helped me in achieving my goal of creating a client websocket control in VB6. I took the version i was working on an stripped it down to a bare-bones version to keep it as simple as possible added an example and have posted it here for your use as you see fit. This project wouldn't have been possible without those people's contributions.

    Hopefully, you will find this useful and beneficial to your web related projects.

    Note, this websocket doesnt support protocol extensions, application layer protocols, and full HTTP header handling, mainly because it doesn't have the full power of a web browser behind it like most websockets. you will be responsible for any data formatting such as JSON, XML etc.. This control only deals with the actual websocket protocol layer. I will be implementing much more functionality into the control as time allows.

    Please post any bugs or questions related to the websocket control below and I will try to fix them as much as possible. If you make any useful additions, please share them so they can be added into the main source code.

    Note: Please direct any questions regarding the SSL code to wqweto as I don't know crap about SSL.

    best regards,
    vbLewis
    Well done, thank you. It would be better if you can add ws function

    I tested and found that ws://127.0.0.1:2007 could not find the service. But I can successfully connect with the web page test
    Last edited by xxdoc123; Aug 1st, 2021 at 07:45 PM.

  7. #7

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Dear xxdoc123.

    There was a bug where the crypto sub system wasn't initialized if a secure socket (wss://) wasn't first used before a non-secure one (ws://) causing the sha1 hash function to fail that is used to authenticate a server regardless of mode. That bug has been squashed in update 1.1

    WS:// is full implemented same as wss:// ... You have to have a local server running in order to connect to a local server. This is a client only control. you can try ws://echo.websocket.org to see that it works.

  8. #8
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    286

    Re: [VB6] Visual Basic 6 Client Websocket Control

    thanks for the update.
    but I still have the same problems.
    to connect
    Quote Originally Posted by yokesee View Post
    Very good work.
    I am trying to connect to the next server, but it gives me problems, it disconnects from the server.

    It works well
    Code:
    wss://echo.websocket.org
    this not

    apikey is real apikey.
    http://piesocket.com
    Code:
    wss://us-nyc-101.piesocket.com/v3/1?api_key=apikey¬ify_self
    Good work, keep it up

  9. #9

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Dear Yokesee,
    The reason you couldnt connect to piesocket was the following:
    1) piesocket apparently doesnt care about standards and makes up their own as they go....
    2) they require a "Content-Type: application/json" header option (completely non-standard)
    3) they dont unencode the query parameters so it completely chokes on encoded server path params (also non-standard)
    4) all data sent after connection must be encoded in json (this is the only thing thats standard)
    5) No sub protocols can be specified, and even if an empty "Sec-Websocket-Protocol" is in the header it will disconnect you (completely non-standard)

    VBWebsocket has been modified to accomodate all piesockets non standard behavior, and you should now be able to connect....
    Just a reminder though... all data needs to be json encoded.

    regards,
    Lewis

  10. #10
    New Member
    Join Date
    Aug 2021
    Posts
    4

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Hello Lewis,

    Let me preface this with a big thank you for working on this control. I know it is challenging.

    I am encountering a subscript out of range error when trying to subscribe to feeds form coinbase.com. It appears that I can connect, but when I send a message, I am immediately disconnected. I compiled the VBWebsocket.vbp into and OCX. When I open the Project1 project, everything is good. When pointing the app toward https://ws-feed.pro.coinbase.com server, I can connect but I am getting a "subscript out of range" message when trying to send a subscription message.

    Is there a way to include the VBWebsocket.vbp files and run everything from source code, instead of adding the .ocx into the toolbar??

    I am an old-school VB programmer from back in the 90's, but has not picked up the keyboard for a couple decades.

  11. #11
    New Member
    Join Date
    Aug 2021
    Posts
    4

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by manaloea View Post
    Hello Lewis,

    Let me preface this with a big thank you for working on this control. I know it is challenging.

    I am encountering a subscript out of range error when trying to subscribe to feeds form coinbase.com. It
    I found the issue. The server in Coinbase that I was subscribing to was the "ticker" feed. This quickly overloaded the list box that displays the server responses. when I changed subscription to a "heartbeat" feed, I was able to see the incoming message.

    Again, many thanks for putting this project together.

  12. #12

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    hi manaloea,

    It appears your use of the websocket is similar to my needs as far as getting crypto feeds and data. There will be a huge update soon that should fix alot of issues. Im glad you found a good use for this project.

  13. #13
    New Member
    Join Date
    Aug 2021
    Posts
    4

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Thank you.

    Now, I am trying to convert your OCX into a DLL to use in VBA-Excel. This is because I wrote some code in VBA to pull Crypto data from Coinbase Pro, and to automatically initiate trades, based on certain criteria. Kinda like an automated day-trader. Excel does a good job of visually and graphically representing data, but hit a wall with websockets. This is probably because the XMLHTTP60 and Internet Controls libraries do not handle the bi-directional communications. But if I can get a DLL to function within the VBA infrastructure, it would be the best of both worlds. Worst case, I will make a bridge between my Excel VBA and your websockets.

  14. #14

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by manaloea View Post
    Thank you.

    Now, I am trying to convert your OCX into a DLL to use in VBA-Excel. This is because I wrote some code in VBA to pull Crypto data from Coinbase Pro, and to automatically initiate trades, based on certain criteria. Kinda like an automated day-trader. Excel does a good job of visually and graphically representing data, but hit a wall with websockets. This is probably because the XMLHTTP60 and Internet Controls libraries do not handle the bi-directional communications. But if I can get a DLL to function within the VBA infrastructure, it would be the best of both worlds. Worst case, I will make a bridge between my Excel VBA and your websockets.
    Sounds very cool. You will want to use the updated 1.3 version as it fixes several very bad bugs. I also included and example of how to use the coinbase ticker. enjoy!

  15. #15
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    286

    Re: [VB6] Visual Basic 6 Client Websocket Control

    very good update.
    Could you help me with a problem with piesocket.com.
    I am logged out every 30 seconds or less.

    greetings and very good job

  16. #16

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by yokesee View Post
    very good update.
    Could you help me with a problem with piesocket.com.
    I am logged out every 30 seconds or less.

    greetings and very good job
    hi yokesee,
    I have narrowed the problem down to a TLS error/Winsock Error. i get the following 2 errors in the system event log "A fatal error occurred while creating a TLS client credential. The internal error state is 10013." after looking up error 10013 (a winsock error) it states "An attempt was made to access a socket in a way forbidden by its access permissions."

    This may take a while to track down but Im looking for a solution and debugging. It may be that piesocket doesnt support tls 1.3 and might need to go back to tls 1.2 etc. not sure.... will let you know when i have a better answer.

    regards,
    lewis

  17. #17
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    España
    Posts
    286

    Re: [VB6] Visual Basic 6 Client Websocket Control

    thanks a lot

  18. #18

    Thread Starter
    Member vbLewis's Avatar
    Join Date
    Feb 2009
    Location
    USA
    Posts
    51

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by yokesee View Post
    thanks a lot
    Dear Yokesee,
    I have found the issue, it was a bug with answering pings silently. I will be posting a bug fix update in a little while after i add some more code to handle buffered frames in ping,pong, and close op code frames.

    for now you can do a quick fix by doing the following...
    In the websocket usercontrol find the function ProcessData and change the following 2 lines of code

    Code:
                    Data(0) = &H8A
                    TlsSock.SendArray Data
    to the following 2 lines of code
    Code:
                    E = ExtractData(Data, DF)
                    TlsSock.SendArray PackMaskData(E, UBound(E) + 1, False, opPong, True)

    that should fix the issue with getting disconnected. I have also enhanced the PieSocket demo which i will be posting with the next update.
    regards,
    lewis

  19. #19
    New Member
    Join Date
    Aug 2021
    Posts
    4

    Re: [VB6] Visual Basic 6 Client Websocket Control

    Quote Originally Posted by vbLewis View Post
    Sounds very cool. You will want to use the updated 1.3 version as it fixes several very bad bugs. I also included and example of how to use the coinbase ticker. enjoy!
    Many Thanks!

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
  •  



Click Here to Expand Forum to Full Width