WebSocket.ahk

Post your working scripts, libraries and tools
GeekDude
Posts: 854
Joined: 02 Oct 2013, 22:13

WebSocket.ahk

28 Jul 2017, 08:00

WebSocket.ahk

Connect to a WebSocket server using AutoHotkey by taking advantage of a hidden ActiveX control.
Note that it does not garbage collect until disconnected.


Usage

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.
		this.WebSock.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
	}
}

Related Projects

Download
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: WebSocket.ahk

14 Oct 2017, 11:46

Thanks! Much easier to use than some of the other WebSocket examples I found. The code is very simple and it works great. :)

I'm using AHKv2 and I only had to switch the + to a . here to make it work for me. I think that change should be better cross-compatible across AHK versions, yes? If so, might be worth making on your master.

Code: Select all

	; Called by the JS in response to WS events
	_Event(EventName, Event)
	{
		this["On" + EventName](Event)
	}
egocarib
Posts: 100
Joined: 21 May 2015, 18:21

Re: WebSocket.ahk

15 Oct 2017, 14:45

It also works without the dot, yes. (I just tend to use it for personal preference)
kevindevm
Posts: 2
Joined: 15 Apr 2019, 23:03

Re: WebSocket.ahk

05 Jun 2019, 16:12

so i use this for a trade site for a game, and all work out but i only can have 6 websocket open when i try to open other one i get this
56619708-d7e84c00-65fc-11e9-8dc8-f327ff4738a1.png
56619708-d7e84c00-65fc-11e9-8dc8-f327ff4738a1.png (14.48 KiB) Viewed 1283 times
basically it say error line 1 character 1 code 0 no url and if i want to continue it will not open the socket, any chance about why this happen? thanks for this

Return to “Scripts and Functions”

Who is online

Users browsing this forum: f1ster and 39 guests