how to send and receive data in realtime Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

how to send and receive data in realtime

Post by ibieel » 05 Jul 2022, 18:39

hey guys, I'm trying to make a script that when pressing F5 on a machine, another machine also presses F5 (with the least possible delay, this is important).
what would be the best way to send/receive data between these machines?
the data content doesn't matter, I just need the send/receive data to trigger the script

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: how to send and receive data in realtime

Post by boiler » 05 Jul 2022, 19:21

Are they on the same network with a shared drive?

User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: how to send and receive data in realtime

Post by ibieel » 06 Jul 2022, 13:19

boiler wrote:
05 Jul 2022, 19:21
Are they on the same network with a shared drive?
for now I'll start as if they were on the same network, but I intend to update to work on different networks.

User avatar
boiler
Posts: 16768
Joined: 21 Dec 2014, 02:44

Re: how to send and receive data in realtime

Post by boiler » 06 Jul 2022, 16:29

I was going to suggest writing to and reading from a shared drive, which I've done on my own network in real time and it worked pretty well, but there's more involved if you're saying you want to communicate through the internet. I'll leave that to others.

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: how to send and receive data in realtime  Topic is solved

Post by neovis » 06 Jul 2022, 20:39

if least possible delay is important to you, It is recommended to use TCP sockets.
viewtopic.php?t=35120

Using SocketTCP class for different networks

User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: how to send and receive data in realtime

Post by ibieel » 06 Jul 2022, 23:25

neovis wrote:
06 Jul 2022, 20:39
if least possible delay is important to you, It is recommended to use TCP sockets.
viewtopic.php?t=35120

Using SocketTCP class for different networks
I managed to send a text as follows:
1- I opened port 8000 on my router
2- I opened port 8000 on my Windows10 computer's firewall (inbound and outbound)

however I had a problem, after a few seconds sending texts via socket the connection error script.
when i restart the script it works for a few more seconds and the connection error again.
I couldn't diagnose the problem, the script is working as follows:

Server Script:

Code: Select all

#NoEnv
SetBatchLines, -1

#Include ..\Socket.ahk

global DC_SERV := True
global DC_CLI := False

Server := new SocketTCP()
Server.OnAccept := Func("OnAccept")
Server.Bind(["0.0.0.0", 8000])
Server.Listen()

OnAccept(Server) {
GLOBAL
	Sock := Server.Accept()
	ToolTip, % Sock.RecvText()
	if (DC_SERV)
		Sock.Disconnect()
}

Client Script:

Code: Select all

#NoEnv
SetBatchLines, -1

#Include ..\Socket.ahk

global DC_SERV := True
global DC_CLI := False


Loop
{
	x := new SocketTCP()
	x.Connect(["187.46.742.551", 8000])	;187.46.742.551 = my global IP
	x.SendText(A_Index)
	Sleep, 10
	if (DC_CLI)
		x.Disconnect()
}
return

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: how to send and receive data in realtime

Post by neovis » 06 Jul 2022, 23:33

Client Script:

Code: Select all

#NoEnv
SetBatchLines, -1

#Include ..\Socket.ahk

global DC_SERV := True
global DC_CLI := False


Loop
{
	x := new SocketTCP()
	x.Connect(["187.46.742.551", 8000])	;187.46.742.551 = my global IP
	x.SendText(A_Index)
	Sleep, 10
	if (DC_CLI)
		x.Disconnect()
}
return
There is no need to put the create a socket in a loop.

Try to like this:

Code: Select all

x := new SocketTCP()
x.Connect(["187.46.742.551", 8000]) ;187.46.742.551 = my global IP
Loop
{
    x.SendText(A_Index)
    Sleep, 10
    if (DC_CLI)
        x.Disconnect()
}

User avatar
ibieel
Posts: 216
Joined: 17 Oct 2021, 23:30

Re: how to send and receive data in realtime

Post by ibieel » 07 Jul 2022, 10:41

neovis wrote:
06 Jul 2022, 23:33

There is no need to put the create a socket in a loop.

Try to like this:

Code: Select all

x := new SocketTCP()
x.Connect(["187.46.742.551", 8000]) ;187.46.742.551 = my global IP
Loop
{
    x.SendText(A_Index)
    Sleep, 10
    if (DC_CLI)
        x.Disconnect()
}


ERROR :(
image.png
image.png (30.75 KiB) Viewed 872 times

User avatar
neovis
Posts: 34
Joined: 12 Jun 2022, 03:56
Location: Republic of Korea
Contact:

Re: how to send and receive data in realtime

Post by neovis » 07 Jul 2022, 22:20

ibieel wrote:
07 Jul 2022, 10:41
ERROR :(
image.png
It seems that the connection is disconnected and the transmission is not possible. Dont disconnect from the server side.

Please remove the code below on the server side.

Code: Select all

	if (DC_SERV)
		Sock.Disconnect()

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: how to send and receive data in realtime

Post by BoBo » 08 Jul 2022, 00:25

@ibieel - you can simply provide AHK's error messages using copy and paste Ctrl+C them. No embedded image necessary. JFTR & HTH ;)

Post Reply

Return to “Ask for Help (v1)”