Cinemizer Posted May 23, 2020 Share Posted May 23, 2020 Hi, I want to write an Autoit program, to receive live streaming data from an Lightstreamer server. If I start following command in cmd.exe on Windows10 PC, it works and the server reply. curl -v -N -X POST -d "LS_adapter_set=WELCOME&LS_cid=mgQkwtwdysogQz2BJ4Ji%20kOj2Bg&LS_send_sync=false" http://push.lightstreamer.com/lightstreamer/create_session.txt?LS_protocol=TLCP-2.1.0 But how can I post and receive live stream with Autoit ? I already so far, that I can send a POST or GET message to a server, but this kind of communication ends the connection, after the server answered. No streaming data can be received after it. I tryed also a socket communication, but it also not works, because I can define there only an IP Address but nothing like "http://push.lightstreamer.com/lightstreamer/create_session.txt?LS_protocol=TLCP-2.1.0". It seems a socket communication is usable only for direct connection to a server over IP and Port Numbers. Please send me an Autoit example how to solve this problem. THX! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 23, 2020 Moderators Share Posted May 23, 2020 Moved to the appropriate forum. Moderation Team Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Danp2 Posted May 23, 2020 Share Posted May 23, 2020 Not the example you were hoping for, but have you looked into using the WinHttp UDF? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
argumentum Posted May 23, 2020 Share Posted May 23, 2020 6 hours ago, Cinemizer said: http://push.lightstreamer ..a can of worms. HTTP is one thing but then you'll wanna do all this with HTTPS and that is another can of worms. You may want to do WebSockets and there we go again. When ppl ask me what coding language I use, my answer is "the one that can get the project out of my hair the easiest". AutoIt my not be that language for this, right now. Now if you ( or someone ), wanna translate WebSockets to TCP/IP in AutoIt ( and that is perfectly possible ), then yes, have a go in AutoIt. ( my 2 cents ) Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Cinemizer Posted May 23, 2020 Author Share Posted May 23, 2020 Hi, Thx, Danp2 ! WinHttp UDF is a good idea, I tested it, seems to work fine with http sites, but does not work with https. I tryed this: If I connect to: http://www.google.com it works, data is coming. But if I want to connect with it to https://www.google.com nothing comes. Why not ? Does the WinHTTP really not support https sites ? Can you recommend me something similar, an UDF which is supporting https or how can I connect with WinHTTp https sites ? THX ! Link to comment Share on other sites More sharing options...
argumentum Posted May 23, 2020 Share Posted May 23, 2020 1 minute ago, Cinemizer said: Can you recommend me something similar, an UDF which is supporting https ..read the help file that is distributed with the UDF. It does handle HTTPS. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Cinemizer Posted May 23, 2020 Author Share Posted May 23, 2020 It is interesting. My code is this: ;***************************************************************** #include "WinHttp.au3" Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "https://www.google.com") Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "") _WinHttpSendRequest($hRequest) _WinHttpReceiveResponse($hRequest) $sHeader = _WinHttpQueryHeaders($hRequest) MsgBox(0, "Header", $sHeader) _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) If I open: "http://www.google.com" I get an answer, but if I open "https://www.google.com", no answer. Why ? Where is the failure ? THX ! Link to comment Share on other sites More sharing options...
Danp2 Posted May 23, 2020 Share Posted May 23, 2020 I imagine it would help if you utilize the correct port. 😎 Try this -- Local $hConnect = _WinHttpConnect($hOpen, "https://www.google.com", $INTERNET_DEFAULT_HTTPS_PORT) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Cinemizer Posted May 24, 2020 Author Share Posted May 24, 2020 THX Danp2 but this did not help. Still no answer if I open: _WinHttpConnect($hOpen, "https://www.google.com", $INTERNET_DEFAULT_HTTPS_PORT) But if I open _WinHttpConnect($hOpen, "http://www.google.com",1234) is working, I mean, it seems not to affect anything, what I write at the end for $iServerPort. It is working with 1234 or with 5555, does not matter, what I write there. Do you have any other idea ? Could you try my script, if it is working/not working same way at you ? THX ! Link to comment Share on other sites More sharing options...
Developers Jos Posted May 24, 2020 Developers Share Posted May 24, 2020 Try this version: #include "WinHttp.au3" Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "www.google.com") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hConnect = ' & $hConnect & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "/") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hRequest = ' & $hRequest & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpSendRequest($hRequest) ConsoleWrite('@@ Debug(>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpReceiveResponse($hRequest) ConsoleWrite('@@ Debug(>Error code: ' & @error & @CRLF) ;### Debug Console $sHeader = _WinHttpQueryHeaders($hRequest) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sHeader = ' & $sHeader & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Cinemizer Posted May 24, 2020 Author Share Posted May 24, 2020 Thx for the script. I have tested it and is still not working, if I open with https:// ________________________________________________________ #include "WinHttp.au3" Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "https://www.google.com") ConsoleWrite('@@ Debug1(' & @ScriptLineNumber & ') : $hConnect = ' & $hConnect & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Local $hRequest = _WinHttpOpenRequest($hConnect, Default, "/") ConsoleWrite('@@ Debug2(' & @ScriptLineNumber & ') : $hRequest = ' & $hRequest & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpSendRequest($hRequest) ConsoleWrite('@@ Debug3(>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpReceiveResponse($hRequest) ConsoleWrite('@@ Debug4(>Error code: ' & @error & @CRLF) ;### Debug Console $sHeader = _WinHttpQueryHeaders($hRequest) ConsoleWrite('@@ Debug5(' & @ScriptLineNumber & ') : $sHeader = ' & $sHeader & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) ________________________________________________________________ I get this answer in console: @@ Debug1(4) : $hConnect = 0x0119A810 >Error code: 0 @@ Debug2(7) : $hRequest = 0x011BB948 >Error code: 0 @@ Debug3(>Error code: 0 @@ Debug4(>Error code: 1 @@ Debug5(16) : $sHeader = >Error code: 1 >Exit code: 0 Time: 0.4141 ____________________________________________________________________________ My problem is not, that I can not open google with https, this address is only for testing. I want to open an other site, which does not work with http, only with https, that´s why I am testing with "https://www.google.com" I guess, as soon it works with "https://www.google.com", my other link will also work. Please help to solve this. THX ! Link to comment Share on other sites More sharing options...
Developers Jos Posted May 24, 2020 Developers Share Posted May 24, 2020 (edited) Ok ...got you. what about this version: #include "WinHttp.au3" Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "https://www.google.com") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hConnect = ' & $hConnect & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $hRequest = _WinHttpSimpleSendSSLRequest($hConnect, "GET", "/") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $hRequest = ' & $hRequest & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $sHeader = _WinHttpQueryHeaders($hRequest) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sHeader = ' & $sHeader & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen) Jos Edited May 24, 2020 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Cinemizer Posted May 24, 2020 Author Share Posted May 24, 2020 (edited) That´s fine, https server is answering ! Thank you very much. I want to connect a server, getting real time data. For that my code is continuing after Local $sHeader = _WinHttpQueryHeaders($hRequest) with: ____________________________________________________________________ While 1 $nMsgArray = GUIGetMsg(1) _WinHttpReceiveResponse($hRequest) If _WinHttpQueryDataAvailable($hRequest) = 1 Then $data=_WinHttpSimpleReadData($hRequest) GUICtrlSetData ($ReturnAnswer_LabelID, $data) ;Writing data onto a label to visualise it EndIf If $nMsgArray[0]<>0 Then ; Exiting if window was closed Switch $nMsgArray[0] Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit EndSwitch EndIf WEnd This reports me continously, that data has been received, but there is coming nothing. Somehow the < If _WinHttpQueryDataAvailable($hRequest) = 1 Then > part does not work. I have red in the WinHTTP.au3 comments, that _WinHttpReceiveResponse($hRequest) must be called before _WinHttpQueryDataAvailable() will be called, but it semms not to work. Do you have an idea, how can I test if data has been received and read data into a $variable ? Many THX! Edited May 24, 2020 by Jos please use the codebox <> for source code :) Link to comment Share on other sites More sharing options...
Danp2 Posted May 24, 2020 Share Posted May 24, 2020 If you look at the coding for _WinHttpSimpleReadData, it is already calling _WinHttpQueryDataAvailable. I also think you need to drop the call to _WinHttpReceiveResponse. Does this work for you? While 1 $nMsgArray = GUIGetMsg(1) $data=_WinHttpSimpleReadData($hRequest) If Not @error Then GUICtrlSetData ($ReturnAnswer_LabelID, $data) ;Writing data onto a label to visualise it EndIf If $nMsgArray[0]<>0 Then ; Exiting if window was closed Switch $nMsgArray[0] Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit EndSwitch EndIf WEnd Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Cinemizer Posted May 24, 2020 Author Share Posted May 24, 2020 Hi, good idea, but also this suggested version from you: ________________________________________________________________________________ $data=_WinHttpSimpleReadData($hRequest) If Not @error Then GUICtrlSetData ($ReturnAnswer_LabelID, $data) ;Writing data onto a label to visualise it MsgBox(0, "Data", $data) EndIf _______________________________________________________________________________ is still signalising, as if a data would have been received, but nothing comes. It means @error is every time <>0, and MsgBox(0, "Data", $data) is coming up in every cycle. I know well, that I sent to the server such a message, which is not complete, so the server would not send me anything. Server sends me only a Header and a type of "Hello, I am here" message, that he understood my message, but does not send me anything. I tryed and this solution works: If Stringlen($data)<>0 Then... It seems, that "If Not @error Then..." does not work. In WinHTTP.au3 at _WinHttpSimpleReadData if no datareceived, it returns: Return SetError(2, 0, $vData) It means @error should be 2 if no data came. Bit interesting, that also If @error<>2 Then... does not work. I do not know, why. Main thing, I have now a solution for it. THX for helping ! Link to comment Share on other sites More sharing options...
Cinemizer Posted May 27, 2020 Author Share Posted May 27, 2020 Hi, I need more help please. I want to create a session on lightstreamer server. If I write following in cmd.exe on windows: curl -v -N -X POST -d "LS_adapter_set=WELCOME&LS_cid=mgQkwtwdysogQz2BJ4Ji%20kOj2Bg&LS_send_sync=false" http://push.lightstreamer.com/lightstreamer/create_session.txt?LS_protocol=TLCP-2.1.0 I get a response from the server. CONOK,session number, x, x, * But if I run following script below, I do not get back anything. Why not ? Where is the failure ? _________________________________________________________________________________________________ Local $hOpen = _WinHttpOpen() Local $hConnect = _WinHttpConnect($hOpen, "http://push.lightstreamer.com/lightstreamer/create_session.txt?LS_protocol=TLCP-2.1.0") Local $hRequest = _WinHttpOpenRequest($hConnect, "POST", "LS_adapter_set=WELCOME&LS_cid=mgQkwtwdysogQz2BJ4Ji%20kOj2Bg&LS_send_sync=false") Local $sHeader = _WinHttpQueryHeaders($hRequest) While 1 $nMsgArray = GUIGetMsg(1) $data=_WinHttpSimpleReadData($hRequest) If Stringlen($data)<>0 Then GUICtrlSetData ($ReturnAnswer_LabelID, $data) ;Writing data onto a label to visualise it EndIf If $nMsgArray[0]<>0 Then Switch $nMsgArray[0] Case $GUI_EVENT_CLOSE ; If X was pressed on the upper right corner GUIDelete($hGUI) Exit EndSwitch EndIf WEnd _____________________________________________________________________________________________ Can you please test the curl line abowe and send me a correct script, which gives me the CONOK answer including the sessionID ? THX ! Link to comment Share on other sites More sharing options...
Danp2 Posted May 27, 2020 Share Posted May 27, 2020 @Cinemizer I'm not an expert with the WinHttp UDF, but I get the feeling that you are doing a couple of things incorrectly -- - You are opening the request, but not actually sending it. See example in help file for _WinHttpOpenRequest where there is a call to _WinHttpSendRequest - Not sure that you can use the standard and "simple" functions interchangeably. HTH, Dan P.S. When you post code in the future please use Code tags - see here how to do it. Then you get a scrolling box, syntax coloring, etc Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now