Socket.ahk

Post your working scripts, libraries and tools for AHK v1.1 and older
geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Socket.ahk

28 Jul 2017, 08:35

Socket.ahk

A socket class based on Bentschi's excellent "Socket Class (überarbeitet)".

Some of the changes that have been made:
  • Instead of accepting the address and port separately, they are passed as a single array of length 2 (similar to python)
  • SendText no longer includes the null terminator
  • The class is self contained and no longer requires an external helper function
Examples
Related projects

Download
zotune
Posts: 85
Joined: 17 Nov 2014, 17:57

Re: Socket.ahk

04 Oct 2017, 18:27

Thanks for the 'socket.ahk' script GeekDude. It's beyond awesome, and a great improvement upon the original.

Do you think you could make an example where you copy a file from client to server? I have yet to figure it out.
iPhilip
Posts: 791
Joined: 02 Oct 2013, 12:21

Re: Socket.ahk

11 Apr 2018, 13:15

Hi GeekDude,

Thank you for the Socket class. I found it easier to use than the AHKsock library by TheGood found here.

For a script that I am working on I dealt with a server that, at times, never responded so I modified the class to include a Timeout parameter as a static variable in the class. I set the default value to 5 seconds. See the updated class below. I marked the modified lines with a ; <<< comment.

Code: Select all

; class Socket by GeekDude - https://autohotkey.com/boards/viewtopic.php?t=35120
; modified by iPhilip to incorporate a timeout check in the Recv() method - see the lines marked by ; <<<

class Socket
{
	static WM_SOCKET := 0x9987, MSG_PEEK := 2
	static FD_READ := 1, FD_ACCEPT := 8, FD_CLOSE := 32
	static Blocking := True, BlockSleep := 50
	static Timeout := 5000  ; <<<
	
	__New(Socket:=-1)
	{
		static Init
		if (!Init)
		{
			DllCall("LoadLibrary", "Str", "Ws2_32", "Ptr")
			VarSetCapacity(WSAData, 394+A_PtrSize)
			if (Error := DllCall("Ws2_32\WSAStartup", "UShort", 0x0202, "Ptr", &WSAData))
				throw Exception("Error starting Winsock",, Error)
			if (NumGet(WSAData, 2, "UShort") != 0x0202)
				throw Exception("Winsock version 2.2 not available")
			Init := True
		}
		this.Socket := Socket
	}
	
	__Delete()
	{
		if (this.Socket != -1)
			this.Disconnect()
	}
	
	Connect(Address)
	{
		if (this.Socket != -1)
			throw Exception("Socket already connected")
		Next := pAddrInfo := this.GetAddrInfo(Address)
		while Next
		{
			ai_addrlen := NumGet(Next+0, 16, "UPtr")
			ai_addr := NumGet(Next+0, 16+(2*A_PtrSize), "Ptr")
			if ((this.Socket := DllCall("Ws2_32\socket", "Int", NumGet(Next+0, 4, "Int")
				, "Int", this.SocketType, "Int", this.ProtocolId, "UInt")) != -1)
			{
				if (DllCall("Ws2_32\WSAConnect", "UInt", this.Socket, "Ptr", ai_addr
					, "UInt", ai_addrlen, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Int") == 0)
				{
					DllCall("Ws2_32\freeaddrinfo", "Ptr", pAddrInfo) ; TODO: Error Handling
					return this.EventProcRegister(this.FD_READ | this.FD_CLOSE)
				}
				this.Disconnect()
			}
			Next := NumGet(Next+0, 16+(3*A_PtrSize), "Ptr")
		}
		throw Exception("Error connecting")
	}
	
	Bind(Address)
	{
		if (this.Socket != -1)
			throw Exception("Socket already connected")
		Next := pAddrInfo := this.GetAddrInfo(Address)
		while Next
		{
			ai_addrlen := NumGet(Next+0, 16, "UPtr")
			ai_addr := NumGet(Next+0, 16+(2*A_PtrSize), "Ptr")
			if ((this.Socket := DllCall("Ws2_32\socket", "Int", NumGet(Next+0, 4, "Int")
				, "Int", this.SocketType, "Int", this.ProtocolId, "UInt")) != -1)
			{
				if (DllCall("Ws2_32\bind", "UInt", this.Socket, "Ptr", ai_addr
					, "UInt", ai_addrlen, "Int") == 0)
				{
					DllCall("Ws2_32\freeaddrinfo", "Ptr", pAddrInfo) ; TODO: ERROR HANDLING
					return this.EventProcRegister(this.FD_READ | this.FD_ACCEPT | this.FD_CLOSE)
				}
				this.Disconnect()
			}
			Next := NumGet(Next+0, 16+(3*A_PtrSize), "Ptr")
		}
		throw Exception("Error binding")
	}
	
	Listen(backlog=32)
	{
		return DllCall("Ws2_32\listen", "UInt", this.Socket, "Int", backlog) == 0
	}
	
	Accept()
	{
		if ((s := DllCall("Ws2_32\accept", "UInt", this.Socket, "Ptr", 0, "Ptr", 0, "Ptr")) == -1)
			throw Exception("Error calling accept",, this.GetLastError())
		Sock := new Socket(s)
		Sock.ProtocolId := this.ProtocolId
		Sock.SocketType := this.SocketType
		Sock.EventProcRegister(this.FD_READ | this.FD_CLOSE)
		return Sock
	}
	
	Disconnect()
	{
		; Return 0 if not connected
		if (this.Socket == -1)
			return 0
		
		; Unregister the socket event handler and close the socket
		this.EventProcUnregister()
		if (DllCall("Ws2_32\closesocket", "UInt", this.Socket, "Int") == -1)
			throw Exception("Error closing socket",, this.GetLastError())
		this.Socket := -1
		return 1
	}
	
	MsgSize()
	{
		static FIONREAD := 0x4004667F
		if (DllCall("Ws2_32\ioctlsocket", "UInt", this.Socket, "UInt", FIONREAD, "UInt*", argp) == -1)
			throw Exception("Error calling ioctlsocket",, this.GetLastError())
		return argp
	}
	
	Send(pBuffer, BufSize, Flags:=0)
	{
		if ((r := DllCall("Ws2_32\send", "UInt", this.Socket, "Ptr", pBuffer, "Int", BufSize, "Int", Flags)) == -1)
			throw Exception("Error calling send",, this.GetLastError())
		return r
	}
	
	SendText(Text, Flags:=0, Encoding:="UTF-8")
	{
		VarSetCapacity(Buffer, StrPut(Text, Encoding) * ((Encoding="UTF-16"||Encoding="cp1200") ? 2 : 1))
		Length := StrPut(Text, &Buffer, Encoding)
		return this.Send(&Buffer, Length - 1)
	}
	
	Recv(ByRef Buffer, BufSize:=0, Flags:=0)
	{
		StartTime := A_TickCount                                                                        ; <<<
		while (!(Length := this.MsgSize()) && this.Blocking && A_TickCount - StartTime < this.Timeout)  ; <<<
			Sleep, this.BlockSleep
		if !Length
			return 0
		if !BufSize
			BufSize := Length
		VarSetCapacity(Buffer, BufSize)
		if ((r := DllCall("Ws2_32\recv", "UInt", this.Socket, "Ptr", &Buffer, "Int", BufSize, "Int", Flags)) == -1)
			throw Exception("Error calling recv",, this.GetLastError())
		return r
	}
	
	RecvText(BufSize:=0, Flags:=0, Encoding:="UTF-8")
	{
		if (Length := this.Recv(Buffer, BufSize, flags))
			return StrGet(&Buffer, Length, Encoding)
		return ""
	}
	
	RecvLine(BufSize:=0, Flags:=0, Encoding:="UTF-8", KeepEnd:=False)
	{
		while !(i := InStr(this.RecvText(BufSize, Flags|this.MSG_PEEK, Encoding), "`n"))
		{
			if !this.Blocking
				return ""
			Sleep, this.BlockSleep
		}
		if KeepEnd
			return this.RecvText(i, Flags, Encoding)
		else
			return RTrim(this.RecvText(i, Flags, Encoding), "`r`n")
	}
	
	GetAddrInfo(Address)
	{
		; TODO: Use GetAddrInfoW
		Host := Address[1], Port := Address[2]
		VarSetCapacity(Hints, 16+(4*A_PtrSize), 0)
		NumPut(this.SocketType, Hints, 8, "Int")
		NumPut(this.ProtocolId, Hints, 12, "Int")
		if (Error := DllCall("Ws2_32\getaddrinfo", "AStr", Host, "AStr", Port, "Ptr", &Hints, "Ptr*", Result))
			throw Exception("Error calling GetAddrInfo",, Error)
		return Result
	}
	
	OnMessage(wParam, lParam, Msg, hWnd)
	{
		Critical
		if (Msg != this.WM_SOCKET || wParam != this.Socket)
			return
		if (lParam & this.FD_READ)
			this.onRecv()
		else if (lParam & this.FD_ACCEPT)
			this.onAccept()
		else if (lParam & this.FD_CLOSE)
			this.EventProcUnregister(), this.OnDisconnect()
	}
	
	EventProcRegister(lEvent)
	{
		this.AsyncSelect(lEvent)
		if !this.Bound
		{
			this.Bound := this.OnMessage.Bind(this)
			OnMessage(this.WM_SOCKET, this.Bound)
		}
	}
	
	EventProcUnregister()
	{
		this.AsyncSelect(0)
		if this.Bound
		{
			OnMessage(this.WM_SOCKET, this.Bound, 0)
			this.Bound := False
		}
	}
	
	AsyncSelect(lEvent)
	{
		if (DllCall("Ws2_32\WSAAsyncSelect"
			, "UInt", this.Socket    ; s
			, "Ptr", A_ScriptHwnd    ; hWnd
			, "UInt", this.WM_SOCKET ; wMsg
			, "UInt", lEvent) == -1) ; lEvent
			throw Exception("Error calling WSAAsyncSelect",, this.GetLastError())
	}
	
	GetLastError()
	{
		return DllCall("Ws2_32\WSAGetLastError")
	}
}

class SocketTCP extends Socket
{
	static ProtocolId := 6 ; IPPROTO_TCP
	static SocketType := 1 ; SOCK_STREAM
}

class SocketUDP extends Socket
{
	static ProtocolId := 17 ; IPPROTO_UDP
	static SocketType := 2  ; SOCK_DGRAM
	
	SetBroadcast(Enable)
	{
		static SOL_SOCKET := 0xFFFF, SO_BROADCAST := 0x20
		if (DllCall("Ws2_32\setsockopt"
			, "UInt", this.Socket ; SOCKET s
			, "Int", SOL_SOCKET   ; int    level
			, "Int", SO_BROADCAST ; int    optname
			, "UInt*", !!Enable   ; *char  optval
			, "Int", 4) == -1)    ; int    optlen
			throw Exception("Error calling setsockopt",, this.GetLastError())
	}
}
Cheers!

- iPhilip
Windows 10 Pro (64 bit) - AutoHotkey v2.0+ (Unicode 64-bit)
txiah

Re: Socket.ahk

04 Oct 2018, 10:32

hello.

I am an old fart programmer but rusty.

I am new to AHK and I need to listen on a socket for an acknowledge from the server before I terminate the client process.

how would I do that?


also is there a script that listens on a socket and returns everything it "sees"?
geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Socket.ahk

04 Oct 2018, 12:21

txiah wrote:hello.

I am an old fart programmer but rusty.

I am new to AHK and I need to listen on a socket for an acknowledge from the server before I terminate the client process.

how would I do that?


also is there a script that listens on a socket and returns everything it "sees"?
Hello txiah, welcome to the AutoHotkey community!

I've written some sample code below that may be able to be
used for these purposes. It listens on TCP socket 1337 for a single newline-delimited line to
be sent, then echoes it to the console. Let me know if any part is unclear or if I there is any other part
you may need help with.

Regards,
GeekDude

Code: Select all

#Include Socket.ahk

; Ask Windows to allocate a console for us to use
; as our output to the user.
DllCall("AllocConsole")

; Set up a queue to contain our received messages,
; and a routine to monitor that queue and carry
; out any work that may be required.
RecvQueue := []
SetTimer, CheckQueue, 100

; Create a socket server to listen for incoming messages.
Server := new SocketTCP()
Server.OnAccept := Func("OnAccept")
Server.Bind(["0.0.0.0", 1337])
Server.Listen()

; Show a dialog to let the user know the server is running
MsgBox, Serving on port 1337`nClose this dialog to exit
ExitApp

; This routine will continually check the RecvQueue
; for newly received messages, and will carry out
; any long-lived or blocking operations that would
; be necessary.
CheckQueue()
{
	global RecvQueue
	
	; Loop through any received messages
	Loop, % RecvQueue.Length()
	{
		; Our newer messages will be at the front
		; of the queue, so remove an item from the
		; first index (AHK arrays are 1-indexed)
		Text := RecvQueue.RemoveAt(1)
		
		; Write the text, with an ending newline,
		; to the console output (Windows exposes
		; the console output as a special file)
		FileAppend, %Text%`n, CONOUT$
	}
}

; We want this routine to run for as little time as possible.
; AutoHotkey is not multithreaded, and while this rotuine
; is running it blocks any other clients from connecting to
; and communiting with the script.
OnAccept(Server)
{
	global RecvQueue
	
	; Accept the socket connection, read one newline-
	; delimited line, then close the socket immediatley.
	; Again, AHK is not multithreaded and can only
	; serve one client at a time, so the less time we
	; spend with the socket open the better.
	Sock := Server.Accept()
	Text := Sock.RecvLine()
	Sock.Disconnect()
	
	; Take the the text we received and put it into
	; the received text queue. Another routine will
	; handle that text and perform any blocking operations,
	; freeing up this routine to be run again for the
	; next client.
	RecvQueue.Push(Text)
}
rIsidoro
Posts: 1
Joined: 05 Feb 2019, 02:21

Re: Socket.ahk

05 Feb 2019, 02:42

Hi all,
I recently began AHK programming. For a small script I made, I used this library so I want to say Thank You to the developer(s).
Also, I would like to contribute a little with a couple of methods I added to the SocketUDP subclass, recvFrom and sendTo, to be used with connectionless protocols like UDP.
They are closely related to recv and send methods. You can add them to the SocketUDP subclass (suggested) or to the main Socket class.
I hope someone may find them useful.

Code: Select all

	RecvFrom(ByRef Buffer, BufSize:=0, Flags:=0, ByRef AddrFrom := 0)
	{
		while (!(Length := this.MsgSize()) && this.Blocking)
			Sleep, this.BlockSleep
		if !Length
			return 0
		if !BufSize
			BufSize := Length
		VarSetCapacity(Buffer, BufSize)
		szAddrFrom := VarSetCapacity(AddrFrom, 16, 0)
		if ((r := DllCall("Ws2_32\recvfrom", "UInt", this.Socket
								, "Ptr", &Buffer, "Int", BufSize
								, "Int", Flags
								, "Ptr", &AddrFrom, "Ptr*", szAddrFrom )) == -1)
			throw Exception("Error calling RecvFrom",, this.GetLastError())
		return r
	}
	
	SendTo(pBuffer, BufSize, Flags:=0, ByRef ToAddr := 0)
	{
		if ((r := DllCall("Ws2_32\sendto", "UInt", this.Socket
						, "Ptr", pBuffer, "Int", BufSize
						, "Int", Flags
						, "Ptr", &ToAddr
						, "Int", 16)) == -1)
			throw Exception("Error calling SendTo",, this.GetLastError())
		return r
	}
Example of use:

Code: Select all

; e.g. in a UDP server, inside a Recv callback function:

VarSetCapacity(pktIN, DGRAMSIZE, 0)
Sock.RecvFrom(pktIN, DGRAMSIZE, 0, addrFrom)
IPfrom := DllCall( "Ws2_32.dll\inet_ntoa","UInt",NumGet(addrFrom,4,"UInt"), "AStr" ) ; IPFrom will contain the IP of the client in string format

; then, after preparing the answer in pktOUT, send it back to the client
Sock.SendTo(&pktOUT, DGRAMSIZE, 0, addrFrom)
Again Thank You G33kDude and Bentschi for the great library.
Bye
Portwolf
Posts: 161
Joined: 08 Oct 2018, 12:57

Re: Socket.ahk

17 Mar 2019, 07:32

Hi there,

I was linked here from Discord. I have no idea on how to use this, looks extremely complicated!
I'll just ask here, hoping someone might help..

I have 2 scripts, on 2 computers.
They are on different networks, and i needed to make script A (sender) send information to script B (receiver).
I am now using One Drive to sync a file with the information, but as it is updated every second, it's really not practical at all.
My objective is that everyone on my team that has script B installed can receive info from script A.

Is this possible?
0x00
Posts: 89
Joined: 22 Jan 2019, 13:12

Re: Socket.ahk

19 Mar 2019, 07:50

Portwolf wrote:
17 Mar 2019, 07:32
Hi there,

I was linked here from Discord. I have no idea on how to use this, looks extremely complicated!
I'll just ask here, hoping someone might help..

I have 2 scripts, on 2 computers.
They are on different networks, and i needed to make script A (sender) send information to script B (receiver).
I am now using One Drive to sync a file with the information, but as it is updated every second, it's really not practical at all.
My objective is that everyone on my team that has script B installed can receive info from script A.

Is this possible?
Not quite, if as you mentioned they're on different' networks, unless you resolve to using noip/dyndns to get a static address through which you can indeed use the functionality provided by this function, but you reminded me of a way i use to do something similar to what you describe, just posted it.
tlk.io bot


Oww, & @G33Kdude, awesome Lib, as always.
User avatar
niczoom
Posts: 78
Joined: 09 Mar 2016, 22:17

Re: Socket.ahk

20 May 2019, 00:27

Hi Geekdude,

I tried the WakOnLan utility above (to wake my TV) and found it didnt work for me. I used the correct MAC address and even tried changing the ip and port numbers in here, UDP.Connect(["255.255.255.255", "7"]) to match the device but with no luck.

Im using it over my wireless network.

Ive installed a WOL app on my phone which does wake my tv so I know it works. Also nirsoft's 'WakeMeOnLan' works via command line.

Any ideas?
[AHK] 1.1.23.05 x32 Unicode
[WIN] 10 Pro x64 Version 5111 (Build 10586.218)
StefC
Posts: 1
Joined: 13 Jan 2020, 12:45

Re: Socket.ahk

13 Jan 2020, 13:14

Hello,

I´m trying to use the the sendText function with the following script:

Code: Select all

#Include ..\Socket.ahk
myTcp := new SocketTCP()
myTcp.Connect(["localhost", 51000])
MsgBox, % myTcp.recvText()
myTcp.SendText("text to send")
The connection is done correctly but the sendText doen't send anything.
I have tried some other scripts that use socket.ahk and sendText but they all fail for me.
When I connect to the port with telnet, everything goes as expected. I don´t understand what I´m doing wrong...
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Socket.ahk

26 May 2020, 06:03

This is an answer for BNOLI from https://www.autohotkey.com/boards/viewtopic.php?p=331482#p331482

There are probably some errors in my code...but this works:
Start the server (the script).
Start on a mobile phone (in wifi) a tcp socket tester as client, add ip of the server, add the port and send a text.
I used the "Simple TCP Socket Tester" https://play.google.com/store/apps/details?id=com.simplesockettester&hl=de and can send text to the serverscript.

Code: Select all

#NoEnv
SetBatchLines, -1
#Include <Socket>
port:=54321
gosub, startserver
return

startserver:
rip := getIP()
MsgBox,% "|" rip "|`n|" port "|"
Server := new SocketTCP()
Server.OnAccept := Func("OnAccept")
Server.Bind([rip, port])
Server.Listen()
return

OnAccept(Server)
{
	Sock := Server.Accept()
	ToolTip, % "send: " Sock.RecvText()
	Sock.Disconnect()
} 

getIP(){
objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
while colItems[objItem]
	loop,4 
    if (objItem.IPAddress[0] == A_IPAddress%a_index%) and !(objItem.DefaultIPGateway[0] = 0)
		return A_IPAddress%a_index%
return
}

blue83
Posts: 157
Joined: 11 Apr 2018, 06:38

Re: Socket.ahk

26 May 2020, 08:29

Hi @haichen , @BNOLI ,

For me this is not working.

Blue
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Socket.ahk

26 May 2020, 09:05

Hi Blue83,
at your mobile did you take the client menu in the tcp socket tester? maybe you took the server menu.
==
pc:
start the ahk-script.
it shows you the ip-adress of your pc and the port i use in the script:
ip 192.168.178.11 (my pc) port 54321

Mobile:
wifi=on
(you must be in the same net as the pc)
App:tcp socket tester
Client-menu ip 192.168.178.11 (example ip of my PC)
port 54321
>connect
then write some text
>send
==
May be you've to open the port in your firewall or
use port 8080 for test. This port may be open.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: Socket.ahk

26 May 2020, 09:29

Hi @haichen, thanks for this! :bravo:

I have an iPhone (inherited, not my phone of choice :P ), the app I use is UDP/TCP/Rest Network Test Utility. Works as client or server. It has a small bug - you may need to select the port address and paste in a new one. If you delete '5001', the stock port, it throws and error. But you can still paste in e.g. '8081'.

I haven't tried port forwarding yet, but I'll do that at some point. Do you think that might work for @blue83's purposes?

Regards,
burque505
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Socket.ahk

26 May 2020, 14:09

Unfortunately I do not know enough about tcp server.
BNOLI
Posts: 548
Joined: 23 Mar 2020, 03:55

Re: Socket.ahk

26 May 2020, 15:42

@haichen The script you've provided worked flawlessly :thumbup: Thx for sharing it! While TCP is the "better" protocol, UDP seems quite interesting regarding smart home stuff (IOT's). Can your script be adapted to work with UDP as well/instead? :) I have the idea that swapping this Server := new SocketTCP() with that Server := new SocketUDP() will doing the trick??! :shifty: ... ?
Remember to use [code]CODE[/code]-tags for your multi-line scripts. Stay safe, stay inside, and remember washing your hands for 20 sec !
User avatar
haichen
Posts: 631
Joined: 09 Feb 2014, 08:24

Re: Socket.ahk

27 May 2020, 02:24

I've tried, but I can't get it to work. Sorry.
I am also very interested in it. Maybe one of the experts could write a tutorial about sockets. I would be very happy about that.
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Socket.ahk

20 Jun 2020, 00:22

geek
Posts: 1051
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Re: Socket.ahk

20 Jun 2020, 14:04

I'm not sure what you intended to imply with that emoji (smilie?), but I wanted to make it clear that I answer questions when I have the time and the answer regardless of where I see them. I don't have good answers for anyone in this thread, nor have I had much time until recently. After the school year ended (hoping to graduate soon :/) I've become more available, though that availability is quickly waning. Since then I've made a couple new releases on this forum (Neutron.ahk, CloudAHK) and have been working hard to help people with their Chrome.ahk troubles by answering questions that I can as they come up in the thread, in private messages here on the forum, through my email, and by collaborating with Joe Glines to put together many hours of learning resources about my libraries. Not because there's any obligation for me to--heck, if I were paid at market rates for this work I'd be eating something nicer than reheated boxed mac for lunch--but because I write code as a hobby and share when I think others may find it useful.

I'm probably "most" active in the Discord if you want to reach me fast, but to say I'm "more" active on Reddit than here is a little misleading as until recently I haven't spent a ton of time commenting either here or there. Though at the moment I am 50% of the active moderator team on Reddit so I spend some extra time "behind the scenes" so to speak.
PublicBenemy
Posts: 6
Joined: 20 Jun 2020, 16:13
Contact:

Re: Socket.ahk

20 Jun 2020, 17:08

Hi there, I'm starting to despair. For hours now, I've been trying to connect to any server device without success.

To avoid any side effects, I used The Simple Socket Tester mentioned by @haichen, and just to try any basic connection. When I run some server thing as AHK script, I can connect from my Android device to the script instance and send messages.
Unfortunately, I am not able to connect from an AHK script to the Android or any other device.

Code: Select all

#Include lib\Socket.ahk

Verbindung := new SocketTCP()
Verbindung.Connect[("192.168.2.198", 4001)]
Verbindung.SendText("Huhu")
To make the pain worse, I cannot find any helpful documentation. All I wanted to do is to read some lousy text the device sends, and I lost a whole afternoon :crazy:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: furqan and 83 guests