how to use Websocket.ahk correctly ?

Get help with using AutoHotkey and its commands and hotkeys
eL Tux
Posts: 66
Joined: 06 Nov 2015, 07:52

how to use Websocket.ahk correctly ?

18 Jul 2020, 21:33

Hi,

I try to use this https://github.com/G33kDude/WebSocket.ahk
I can send message one time but how to send multiple message ?

I tried to add a fire key (F4) like this :

Code: Select all

#NoEnv
SetBatchLines, -1

#Include WebSocket.ahk

F4::

new Example("wss://mywebsocket....")
return


class Example extends WebSocket
{
	OnOpen(Event)
	{
		InputBox, Data, WebSocket, Enter some text to send through the websocket.
		this.Send(Data)
	}
	
	OnMessage(Event)
	{
		MsgBox, % "Received Data: " Event.data
		this.Close()
	}
	
	OnClose(Event)
	{
		MsgBox, Websocket Closed
		this.Disconnect()
	}
	
	OnError(Event)
	{
		MsgBox, Websocket Error
	}
	
	__Delete()
	{
		MsgBox, Exiting
		ExitApp
	}
}
But this is not work correctly because when I send a message I receive an echo.
So how to send multiple messages without having echo ?

Sorry for my poor english,
Thanks
burque505
Posts: 1358
Joined: 22 Jan 2017, 19:37

Re: how to use Websocket.ahk correctly ?

08 Aug 2020, 14:12

@eL Tux, sorry I missed this post last month. Try this:

Code: Select all

#NoEnv
SetBatchLines, -1

#Include ../WebSocket.ahk

new Example("wss://echo.websocket.org/")
return


class Example extends WebSocket
{
	OnOpen(Event)
	{
		InputBox, Data, WebSocket, Enter some text to send through the websocket.
		If (ErrorLevel==1)
			this.Close()
		this.Send(Data)
	}
	
	OnMessage(Event)
	{
		MsgBox, % "Received Data: " Event.data
		new Example("wss://echo.websocket.org/")
	}
	
	OnClose(Event)
	{
		MsgBox, Websocket Closed
		this.Disconnect()
	}
	
	OnError(Event)
	{
		MsgBox, Websocket Error
	}
	
	__Delete()
	{
		MsgBox, Exiting
		ExitApp
	}
}
Regards,
burque505

Return to “Ask For Help”

Who is online

Users browsing this forum: aurelius, Bv841455, ddt442, Google [Bot], hasantr, jadams, mikeyww, pelos, teadrinker and 33 guests