Author Topic: My Next Experiment  (Read 300 times)

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
My Next Experiment
« on: March 29, 2021, 10:24:02 am »
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

  • Tech Support
  • *****
  • Posts: 3745
    • WinBatch
Re: My Next Experiment
« Reply #1 on: March 29, 2021, 10:38:51 am »
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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #2 on: March 29, 2021, 10:52:04 am »
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

  • Tech Support
  • *****
  • Posts: 3745
    • WinBatch
Re: My Next Experiment
« Reply #3 on: March 29, 2021, 01:30:25 pm »
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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #4 on: March 29, 2021, 03:36:34 pm »
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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #5 on: March 31, 2021, 10:39:32 am »
Curious if anyone has tried this and if it worked???

Jim

kdmoyers

  • Sr. Member
  • ****
  • Posts: 411
Re: My Next Experiment
« Reply #6 on: March 31, 2021, 12:42:20 pm »
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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #7 on: March 31, 2021, 01:16:17 pm »
Probably not.   Would only be useful if hitting a websocket server.

Jim

stanl

  • Pundit
  • *****
  • Posts: 1446
Re: My Next Experiment
« Reply #8 on: April 01, 2021, 02:48:09 am »
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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #9 on: April 01, 2021, 03:10:18 pm »
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

  • Pundit
  • *****
  • Posts: 1446
Re: My Next Experiment
« Reply #10 on: April 02, 2021, 03:27:38 am »
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

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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #11 on: April 02, 2021, 06:24:00 am »
Don't mind adding it.   Just wanted to make sure we were on the same page.

Jim

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #12 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.


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


Jim

stanl

  • Pundit
  • *****
  • Posts: 1446
Re: My Next Experiment
« Reply #13 on: April 03, 2021, 03:28:48 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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #14 on: April 03, 2021, 06:36:42 am »
I apologize.   Not sure how I did that...

b64Encode() and b64Decode().


Jim

stanl

  • Pundit
  • *****
  • Posts: 1446
Re: My Next Experiment
« Reply #15 on: April 03, 2021, 06:45:10 am »
I apologize.   Not sure how I did that...
b64Encode() and b64Decode().


No worries: looks good compared to CLR
Code: Winbatch

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

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #16 on: April 03, 2021, 07:27:18 am »
Excellent.  Thanks.

Jim

JTaylor

  • Pundit
  • *****
  • Posts: 1667
    • Data & Stuff Inc.
Re: My Next Experiment
« Reply #17 on: April 03, 2021, 12:33:13 pm »
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