Jump to content

how to get websocket


aldo
 Share

Recommended Posts

Welcome to AutoIt and the forum!
What have you tried so far?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Hello. consider use a lenguage recommended by the page. Maybe javascript otherwise you can use Winhttp UDF but you must use Windows 8 or upper. Also You can do a  trick mixing Javascript and IE.

You mush create it in your account.

Saludos

Edited by Danyfirex
Link to comment
Share on other sites

Here is the direct link which I found in the API Playground... It redirects to the login page, a registration will get you the API key :) (as already mentioned by @Danyfirex :P)

 

P.S A word of advice, This forum provides support for problems with AutoIt... not with external matters! You can post questions NOT related to AutoIt in the Language Specific sub-forum or Chat (Not accessible to new members) sub-forum forum :)

P.P.S I just found out there is a Glitter Chat Room (for Binary [That API's provider] developers). Although you need a GitHub account to chat :).

Edited by TheDcoder
Appended P.P.S

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 1 month later...

This sample code javascript from websocket

who can help me to convert to au3

 

var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3');

ws.onopen = function(evt) {
    ws.send(JSON.stringify({ticks:'R_100'}));
};

ws.onmessage = function(msg) {
   var data = JSON.parse(msg.data);
   console.log('ticks update: %o', data);
};

 

 

Link to comment
Share on other sites

1 hour ago, mendrofa said:

 


var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3');

ws.onopen = function(evt) {
    ws.send(JSON.stringify({ticks:'R_100'}));
};

ws.onmessage = function(msg) {
   var data = JSON.parse(msg.data);
   console.log('ticks update: %o', data);
};

How did you do that!? :shocked:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

You can do it using Winhttp (I'm really busy I'll will not traslate to Autoit) .  (make sure using AutoIt for that. it will not be so stable.

https://github.com/uri247/Win81Desktop/tree/master/WinHTTP%20WebSocket%20sample

Saludos

Link to comment
Share on other sites

this my code

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 233, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 297, 217)
$Input1 = GUICtrlCreateInput("9QeuqAtACdcvjIW", 24, 24, 177, 21)
$Button1 = GUICtrlCreateButton("conect socket", 207, 24, 91, 25)
$Edit1 = GUICtrlCreateEdit("", 24, 56, 273, 153)
GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
    case $nmsg = $button1
       tes()
        Case $nmsg =  $GUI_EVENT_CLOSE
            Exit

    EndSelect
WEnd

func tes()
Local $sIPAddress = "wss://ws.binaryws.com/websockets/v3" ; This IP Address only works for testing on your own computer.
    Local $iPort = guictrlread($input1) ; Port used for the connection.

    ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    sleep(5000)
Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
guictrlsetdata($edit1, $iListenSocket)


   EndFunc

Link to comment
Share on other sites

NB: Could you please use code tags when posting a script? Makes reading your code much easier ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 233, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 297, 217)
$Input1 = GUICtrlCreateInput("9QeuqAtACdcvjIW", 24, 24, 177, 21)
$Button1 = GUICtrlCreateButton("conect socket", 207, 24, 91, 25)
$Edit1 = GUICtrlCreateEdit("", 24, 56, 273, 153)
GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
    case $nmsg = $button1
       tes()
        Case $nmsg =  $GUI_EVENT_CLOSE
            Exit

    EndSelect
WEnd

func tes()
Local $sIPAddress = "wss://ws.binaryws.com/websockets/v3" ; This IP Address only works for testing on your own computer.
    Local $iPort = guictrlread($input1) ; Port used for the connection.

    ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    sleep(5000)
Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)
guictrlsetdata($edit1, $iListenSocket)


   EndFunc

 

Link to comment
Share on other sites

Thanks :)
But you could as well have modified post #12 ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

You need to add some error checking after TCPConnect and TCPListen.
What is the return value and the value of @error?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

like that

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 233, 192, 124)
$Group1 = GUICtrlCreateGroup("", 8, 8, 297, 217)
$Input1 = GUICtrlCreateInput("9QeuqAtACdcvjIW", 24, 24, 177, 21)
$Button1 = GUICtrlCreateButton("conect socket", 207, 24, 91, 25)
$Edit1 = GUICtrlCreateEdit("", 24, 56, 273, 153)
GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Select
    case $nmsg = $button1
       tes()
        Case $nmsg =  $GUI_EVENT_CLOSE
            Exit
            endSelect
WEnd

func tes()
Local $sIPAddress = "wss://ws.binaryws.com/websockets/v3" ; This IP Address only works for testing on your own computer.
    Local $iPort = guictrlread($input1) ; Port used for the connection.

    ; Assign a Local variable the socket and connect to a Listening socket with the IP Address and Port specified.
    Local $iSocket = TCPConnect($sIPAddress, $iPort)
    If @error Then
        ; The server is probably offline/port is not opened on the server.
        Local $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not connect, Error code: " & $iError)
        Return False
    Else
        MsgBox($MB_SYSTEMMODAL, "", "Connection successful")
    EndIf

Local $iListenSocket = TCPListen($sIPAddress, $iPort, 100)

Local $iError = 0

    ; If an error occurred display the error code and return False.
    If @error Then
        ; Someone is probably already listening on this IP Address and Port (script already running?).
        $iError = @error
        MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not listen, Error code: " & $iError)
        Return False
    EndIf

    ; Assign Local variable to be used by Listening and Client sockets.
    Local $iSocket = 0
    Do ; Wait for someone to connect (Unlimited).
        ; Accept incomming connexions if present (Socket to close when finished; one socket per client).
        $iSocket = TCPAccept($iListenSocket)

        ; If an error occurred display the error code and return False.
        If @error Then
            $iError = @error
            MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Could not accept the incoming connection, Error code: " & $iError)
            Return False
        EndIf
    Until $iSocket <> -1 ;if different from -1 a client is connected.

    ; Close the Listening socket to allow afterward binds.
    TCPCloseSocket($iListenSocket)

    MsgBox($MB_SYSTEMMODAL, "", "Client Connected.")
















guictrlsetdata($edit1, $iListenSocket)


   EndFunc

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...