I have an application I want to run ahkv1 side by side with ahkv2 and communicate through Socket.ahk found here:https://github.com/TheArkive/Socket_ahk2
I'm new to sockets but I have worked with them before, never passing and handling packets, always in some abstract form.
For this conversation I'll keep it to AHKv2 as Im getting stuck at just replicating the example server//client relationship where I want to send a string from the former to the latter.
Problem: Only getting IP address in return, no string
In the example I have taken test_server() and test_send() functions from : https://github.com/TheArkive/Socket_ahk2/blob/master/_socket_example.ahk
mentioned code:
Code: Select all
test_server() {
sock := winsock("server",cb,"IPV4")
sock.Bind("0.0.0.0",27015) ; "0.0.0.0",27015
sock.Listen()
}
test_send() {
sock := winsock("client", cb, "IPV4")
If !(r := sock.Connect("127.0.0.1", 27015, true)) { ; connect as blocking, setting param #3 to TRUE
msgbox "Could not connect."
return ; handle a failed connect properly
}
msg := "abc"
strbuf := Buffer(StrLen(msg) + 1) ; for UTF-8, take strLen() + 1 as the buffer size
StrPut(msg, strbuf, "UTF-8")
r := sock.Send(strbuf) ; check send result if necessary
sock.Close()
}
the first script runs test_server() listening for me to start test_send() back and (my basic goal) is to show a msgbox denoting it has worked, with the string.
Code: Select all
buf := sock.Recv()
msgbox("======================`r`n"
. "Server recieved from client:`r`n"
. Trim(strget(buf,"UTF-8"),"`r`n") "`r`n"
. "======================`r`n`r`n")
global return_string := Trim(strget(buf,"UTF-8")
and then I check for return_string values:
Code: Select all
global return_string := ""
Settimer(waiter, 250)
waiter(){
global return_string
if return_string != "" {
msgbox(returnstring)
return_string := ""
}
}