Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Raw" (OBS) Websocket ws:// communication (_OpenClient, Get, Put), is it possible?
#1
I looked into this some time back but came to the conclusion that it's not possible with QB64, however, I never asked the good people here, who are much more knowledgeable than I.

Here is the documentation with connection steps: https://github.com/obsproject/obs-websoc...tion-steps

I understand the process with HTTP and sending headers etc ("User-Agent: curl/8.1.2" for example), and doing a search, this post suggests it might be possible, but there's no code to investigate https://qb64phoenix.com/forum/showthread...0#pid12740
Reply
#2
It might be possible, but this stuff looks very deep. You might have to dedicate yourself to C++ more than you might want to, and more than I would want to because I am on BASIC's side too much. Might have to use some function calls from there and figure out what is the library (file extension DLL or SO) to link with the QB64 program. Pay attention to the license for those libraries... this is a PITA with LGPL and those other variations.

This might be easiest on Windows through the API, if the libraries were written by Microsoft. Otherwise I'm naive enough to think this type of functionality would be available on Unix and descendants.

I almost forgot to mention that it might be possible, while the "HTTPS" functionality gets away from `$UNSTABLE` status. It could be tried first with the QB64 commands, but it's going to depend on the server response and how much it might require the dedicated library.
Reply
#3
It looks possible in QB64. It's just TCP. Smile

https://developer.mozilla.org/en-US/docs...et_servers

That said, it's over my head to help further than provide this link. Smile

If you get it working, that'd be pretty cool.

What are you planning to build in QB64 for OBS?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#4
(09-11-2023, 12:04 PM)loopy750 Wrote: I looked into this some time back but came to the conclusion that it's not possible with QB64, however, I never asked the good people here, who are much more knowledgeable than I.

Here is the documentation with connection steps: https://github.com/obsproject/obs-websoc...tion-steps

I understand the process with HTTP and sending headers etc ("User-Agent: curl/8.1.2" for example), and doing a search, this post suggests it might be possible, but there's no code to investigate https://qb64phoenix.com/forum/showthread...0#pid12740
It's definitely possible, but it would be a bit of a pain. Doing it via a TCP/IP client would require implementing both the HTTP protocol and the WebSockets protocol yourself, which is possible but hard. Additionally doing it with SSL/TLS security would be even harder since you'd need to get a TLS library in the mix there somewhere (there's little hope of implementing that yourself).

In regards to what @mnrvovrfc mentioned, QB64-PE does have built-in HTTP and HTTPS support, but currently it can't be used to open a WebSockets connection. Based on the libcurl documentation we could probably add that in the future, but there's no timeline on that. Potentially you could interact with `libcurl` yourself to do it but you'd really need to use a bit (or a lot) of C++ for that.
Reply
#5
Luke gave us a lecture on TCP/IP at .org
https://qb64forum.alephc.xyz/index.php?t...#msg115999

I think Fellippe did a video interview on the subject with Luke.

I know Steve knows this stuff too, is he well enough to recall @SMcNeill ?
b = b + ...
Reply
#6
Thanks for all the responses so far, I'm reading all of it, and there's definitely a lot of reading to do, although I'm not sure how much I can comprehend vs how much will go over my head, hence why I need some assistance.

Also, I've added some code on the "direction" I think it could go, but I could be completely wrong, and if that is the case, hopefully I can be aware of that sooner rather than later, otherwise I'll be spending time on code that will just lead to a dead end. This is an example:

If you have OBS open and Websocket enabled, you should see the response "HTTP/1.1 400 Server: WebSocket++/0.8.2", so I'm least getting some sort of a response... note that the code is just a hot mess, " Content-Length " for example I've needed for another scenario, but may or may not even be needed in this case.

Code: (Select All)
Common Shared WS_Port_Client As String, WS_Server_Port As String, WS_EOL As String, WS_Server_IP As String, WS_Password As String, WS_Header As String, WS_Data As String
Common Shared c34 As String

WS_EOL = Chr$(13) + Chr$(10)
c34 = Chr$(34)

WS_Server_Port = "4455"
WS_Server_IP = "127.0.0.1"
WS_Password = "TBD"

WS_Port_Client = "TCP/IP:" + WS_Server_Port + ":"

WS_Data = "{" + c34 + "sceneName" + c34 + ":" + c34 + "BRB" + c34 + "}"


ws_client = _OpenClient(WS_Port_Client + WS_Server_IP)

WS_Header = ""

WS_Header = WS_Header + "WHAT GOES HERE?" + WS_EOL

WS_Header = WS_Header + "Content-Length: " + _Trim$(Str$(Len(WS_Data))) + WS_EOL + WS_EOL
WS_Header = WS_Header + WS_Data


Put #ws_client, , WS_Header


b$ = ""
While b$ = ""
    Get #ws_client, , b$
Wend
Print b$
Reply
#7
Using info from this page: https://wiki.wireshark.org/WebSocket

Now reports HTTP/1.1 101 Switching Protocols


Code: (Select All)
Common Shared WS_Port_Client As String, WS_Server_Port As String, WS_EOL As String, WS_Server_IP As String, WS_Password As String, WS_Header As String, WS_Data As String
Common Shared c34 As String

WS_EOL = Chr$(13) + Chr$(10)
c34 = Chr$(34)

WS_Server_Port = "4455"
WS_Server_IP = "127.0.0.1"
WS_Password = "TBD"

WS_Port_Client = "TCP/IP:" + WS_Server_Port + ":"

WS_Data = "{" + c34 + "sceneName" + c34 + ":" + c34 + "BRB" + c34 + "}"


ws_client = _OpenClient(WS_Port_Client + WS_Server_IP)

WS_Header = ""

WS_Header = WS_Header + "GET / HTTP/1.1" + WS_EOL
WS_Header = WS_Header + "Host: 127.0.0.1:4455" + WS_EOL
WS_Header = WS_Header + "Connection: Upgrade" + WS_EOL
WS_Header = WS_Header + "Pragma: no-cache" + WS_EOL
WS_Header = WS_Header + "Cache-Control: no-cache" + WS_EOL
WS_Header = WS_Header + "Upgrade: websocket" + WS_EOL
WS_Header = WS_Header + "Origin: file://" + WS_EOL
WS_Header = WS_Header + "Sec-WebSocket-Version: 13" + WS_EOL
'WS_Header = WS_Header + "Sec-WebSocket-Protocol: obswebsocket.msgpack" + WS_EOL
WS_Header = WS_Header + "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36" + WS_EOL
WS_Header = WS_Header + "Accept-Encoding: gzip, deflate, sdch" + WS_EOL
WS_Header = WS_Header + "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4" + WS_EOL
WS_Header = WS_Header + "Sec-WebSocket-Key: bKdPyn3u98cTfZJSh4TNeQ==" + WS_EOL
WS_Header = WS_Header + "Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits" + WS_EOL + WS_EOL

Put #ws_client, , WS_Header


b$ = ""
While b$ = ""
    Get #ws_client, , b$
Wend
Print b$
Reply




Users browsing this thread: 2 Guest(s)