My Next Experiment

Started by JTaylor, March 29, 2021, 10:24:02 AM

Previous topic - Next topic

JTaylor

I have been playing around with websockets off and on for a while and decided to see if I could make it work within an Extender.  I am quite ignorant though of how websockets get used in the real world so not sure if this accomplishes anything useful.   Just the client, of course.   Also, it currently doesn't support secure websockets.   Didn't want to waste time if this turned out to be a bad idea.   You do need to provide your own websocket server info in the script.   The only thing I can say about what I have provided here is that it works with my websocket server :) 

Like the Events it uses the Timer event.

    http://www.jtdata.com/anonymous/wbOmnibus.zip

See the Help file for more info.

Just curious if anyone would find this functionality useful within WinBatch.   I have been working on a chat client but it is using an embedded web browser control and thought I would give this a try.

Jim

td

Out of an abundance of curiosity and assuming you are using one which client library are you using?
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

EasyWSClient for now.  Wanted something that didn't require Boost or Asio (which are few and far between).    Just ran across libwebsockets.org but haven't had time to figure out if that would be a better choice.

https://github.com/dhbaird/easywsclient

Jim

td

Boost is a very popular beast. I guess WinBatch developers have had so many home-baked algorithm implementations around over the years that need never arose. I can see that changing in the future, however.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

JTaylor

Nice play on Boost and Beast :)   Yes.   Was having trouble finding anything that didn't use it, and even tried using it, but kept hitting problems and when I finally found one that didn't have any extra dependencies I happily switched.

Jim

JTaylor

Curious if anyone has tried this and if it worked???

Jim

kdmoyers

I don't have a ready application for this one, sorry.

I future, I'll have a reason to do some RESTful API calls, would this be useful for that application?
(please forgive my web services ignorance)

-Kirby
The mind is everything; What you think, you become.

JTaylor

Probably not.   Would only be useful if hitting a websocket server.

Jim

stanl

Quote from: JTaylor on March 31, 2021, 01:16:17 PM
Probably not.   Would only be useful if hitting a websocket server.

Jim


as for Rest queries.... your extender does provide json support (as that is a popular restful return). You could consider adding a function for base64 authentication (also popular).

JTaylor

Sorry, wasn't ignoring you...

How would you see this working?    Just providing a way to encode credentials passed to the function, which one could use in a call, or something more involved?

Jim

stanl

Quote from: JTaylor on April 01, 2021, 03:10:18 PM
How would you see this working?    Just providing a way to encode credentials passed to the function, which one could use in a call, or something more involved?


Basic authentication with base64 is not that complicated {or secure ::) } a few lines of CLR code with ObjectClrNew('System.Text.Encoding') and ObjectClrNew('System.Convert') and I think there is a base64 extender and some older UDF's in the Tech DB.  But if it wouldn't be that difficult to package in your Extender it would help with WinHTTP API requests...


Code (WINBATCH) Select


user = 'winbatch'
pw   = '$ecretF!le'
pair = user:":":pw

request = Createobject("WinHttp.WinHttpRequest.5.1")
request.Open("GET", [myURL], @False )
request.SetRequestHeader("Authorization", "Basic ":base64String(pair))
; etc...etc









where base64String() is your function. I know I will use your Extender for the Json and SQlite functionality with web requests so a function like that would be an extra benefit. But others might not see it that way... so maybe put it up for a vote.

JTaylor

Don't mind adding it.   Just wanted to make sure we were on the same page.

Jim

JTaylor

Give this a whirl and let me know if it does what you want...info under Base64 Topic in Help file.


    http://www.jtdata.com/anonymous/wbOmnibus.zip


Jim

stanl

Quote from: JTaylor on April 02, 2021, 07:32:22 AM
Give this a whirl and let me know if it does what you want...info under Base64 Topic in Help file.



functions are in help file but trying to call b64Encoding() gives undefined function error..

JTaylor

I apologize.   Not sure how I did that...

b64Encode() and b64Decode().


Jim

stanl

Quote from: JTaylor on April 03, 2021, 06:36:42 AM
I apologize.   Not sure how I did that...
b64Encode() and b64Decode().


No worries: looks good compared to CLR
Code (WINBATCH) Select


AddExtender("c:\scripts\dom\wbOmnibus.dll")  ;change path
user = 'winbatch'
pw   = '$ecretF!le'
pair = user:":":pw
omni =  b64Encode(pair)
oEncode = ObjectClrNew('System.Text.Encoding')
oCvt    = ObjectClrNew('System.Convert')
oAsc    = oEncode.ASCII
bUser   = oCvt.ToBase64String(oAsc.GetBytes(user))
bPW     = oCvt.ToBase64String(oAsc.GetBytes(pw))
bPair   = oCvt.ToBase64String(oAsc.GetBytes(pair))
message("Base64",BUser:@LF:BPW:@LF:bPair:@LF:omni)

JTaylor


JTaylor

I also added the ability to display various image formats in a dialog PICTURE control.  Actually most any control will work, including the dialog itself.   Any that are update-able, like an editbox, will revert to its original background when you start typing.   So a StaticText or VaryText would generally work okay as well since you don't alter those other than programmatically.   I could see times though when you might want to start with a graphic in an edit box or a mulitline box.

   imPicToGraphic()

It has its limitations (explained in help) but seems to work well.    Open to suggestions for the function name.   Was having trouble thinking of a good one.


     http://www.jtdata.com/anonymous/wbOmnibus.zip


Jim

bmclellan

Well, I'm a year and a half late to the party! I'm going to give this a shot!