Author Topic: Websocket protocol possible?  (Read 2861 times)

0 Members and 1 Guest are viewing this topic.

Offline lpy

  • Newbie
  • Posts: 6
    • View Profile
Websocket protocol possible?
« on: July 22, 2020, 06:55:03 pm »
Hi. I'm trying to use Websocket, specifically OBS Websocket, to send/receive commands. I can connect and get a "HTTP/1.1 101 Switching Protocols" response, but that's as far as it goes so far. Anyone know if this is possible in QB64?

Some useful links:
https://www.qb64.org/forum/index.php?topic=2041.0
http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index_PHPSESSID_gulg2aoa966472fnfhjkgp4i35_topic_7287-15/
https://github.com/Palakis/obs-websocket/blob/4.x-current/docs/generated/protocol.md

Code: QB64: [Select]
  1. hostWebsocket$ = "127.0.0.1"
  2. portWebsocket$ = "4444"
  3. client = _OPENCLIENT("TCP/IP:" + portWebsocket$ + ":" + hostWebsocket$)
  4. file$ = ""
  5. EOL = CHR$(13) + CHR$(10)
  6. xHeader1$ = "GET /" + file$ + " HTTP/1.1"
  7. xHeader2$ = "User-Agent: websocket-sharp/1.0"
  8. xHeader3$ = "Host: " + hostWebsocket$ + ":" + portWebsocket$
  9. xHeader4$ = "Upgrade: websocket"
  10. xHeader5$ = "Connection: Upgrade"
  11. xHeader6$ = "Cache-Control: no-cache"
  12. xHeader7$ = "Sec-WebSocket-Key: rLtppj9rr1DwGJEPgS9dGg=="
  13. xHeader8$ = "Sec-WebSocket-Version: 13"
  14. x$ = xHeader1$ + EOL + xHeader2$ + EOL + xHeader3$ + EOL + xHeader4$ + EOL + xHeader5$ + EOL + xHeader6$ + EOL + xHeader7$ + EOL + xHeader8$ + EOL + EOL + EOL
  15. PUT #client, , x$
  16. Timer_GET! = TIMER
  17.     GET #client, , a2$
  18.     PRINT a2$;
  19. LOOP UNTIL TIMER > Timer_GET! + 1
  20. CLOSE client
  21.  

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Websocket protocol possible?
« Reply #1 on: July 23, 2020, 10:18:46 am »
You can take a look at CURL. You can shell out to it from QB64. My post here : https://www.qb64.org/forum/index.php?topic=2841.msg121044#msg121044 shows using CURL to use custom headers and get the response. I'd be happy to help you out with this if you need further assistance.
Shuwatch!

Offline lpy

  • Newbie
  • Posts: 6
    • View Profile
Re: Websocket protocol possible?
« Reply #2 on: July 23, 2020, 03:30:36 pm »
Thanks for your assistance. curl is interesting.. I can send headers much like qb64 PUT, but that's where I'm kinda stuck. There is an external program I can SHELL to, but I'm trying to work out how to avoid doing that and simply do everything "internally" using GET and PUT to do everything I need to. For loading a webpage it's obviously much more simple... you send a few headers and get the response, but websocket is a protocol I don't fully understand, especially with authorising (sending password "hashed", etc).