I rewrote the UDP script for broadcast(local network):
- WSAASyncSelect create a "real-time" with UDP
- two sockets ( for to receiv and to send) is better
- script can send one message to a specified address
- display the connection/disconnection
It seems that the broadcast feature is only for IPV4

and this script is for run one time per computer ( can't recreate the same socket at same address:port )
Sorry to pollute the forum is a bit like a log, but I think this script can be usefull for network admin
Code:
Port = 8787 ; choice a port
Gui, Add, Edit, w320 r10 vLogEdit ReadOnly,
Gui, Add, Edit, section w200 R1 Limit255 vsenddata,
Gui, Add, Button, ys gSendButton, Send
Gui, Show,, Tiny UDP
OnExit, ExitSub
; ----------------------------------------------------------------
VarSetCapacity(wsaData, 32, 0)
DllCall("Ws2_32\WSAStartup", "UShort", 0x202, "UInt", &wsaData)
recvsock := DllCall("Ws2_32\socket", "Int", 2, "Int", 2, "Int", 17)
VarSetCapacity(recvaddr, 32, 0)
NumPut(2, recvaddr, 0, "Short")
NumPut(DllCall("Ws2_32\htons", "UShort", Port), recvaddr, 2, "UShort")
DllCall("Ws2_32\bind", "UInt", recvsock, "UInt", &recvaddr, "Int", 32)
sendsock := DllCall("Ws2_32\socket", "Int", 2, "Int", 2, "Int", 17)
VarSetCapacity(toaddr, 32, 0)
NumPut(2, toaddr, 0, "Short")
NumPut(DllCall("Ws2_32\htons", "UShort", Port), toaddr, 2, "UShort")
NumPut(0xFFFFFFFF, toaddr, 4, "UInt")
VarSetCapacity(broadcast,16) , broadcast = 1
DllCall("Ws2_32\setsockopt", "UInt", sendsock, "UInt", 0xFFFF, "UInt", 0x20, "UInt", &broadcast, "Int", 16)
DllCall("Ws2_32\WSAAsyncSelect", "UInt", recvsock, "UInt", WinExist("A"), "UInt", 0x5555, "Int", 0x1)
OnMessage(0x5555, "WinsockMessage")
if ( log := DllCall("Ws2_32\WSAGetLastError") ) {
msgbox WinSock error %log%
exitapp
}
else {
log := "Tiny UDP ready ! " a_IPAddress1 ":" Port
Guicontrol,, LogEdit, %log%
DllCall("Ws2_32\sendto", "UInt", sendsock, "Str", "connected", "UInt", 9, "UInt", 0x4, "UInt", &toaddr, "UInt", 32)
}
return
; ----------------------------------------------------------------
WinsockMessage(socket, event)
{
Critical
global log, recvsock
VarSetCapacity(recvdata, 256, 0)
VarSetCapacity(fromaddr, 32, 0)
VarSetCapacity(buff, 64)
DllCall("Ws2_32\recvfrom", "UInt", recvsock, "Str", recvdata, "UInt", 256, "UInt", 0, "UInt", &fromaddr, "UInt", &buff)
log .= "`n" NumGet(fromaddr, 4, "UChar")
loop 3
log .= "." NumGet(fromaddr, 4+A_Index, "UChar")
log .= " : " recvdata
; if recvdata = myaction then gosub mylabel
Guicontrol,, LogEdit, %log%
controlsend, edit1, ^{end}, Tiny UDP
}
; ----------------------------------------------------------------
SendButton:
GuiControlGet, senddata
If ( senddata="connected" || senddata="disconnected" )
return
If ( InStr(senddata, "/")=1 && pos:=InStr(senddata, " ") ) {
log .= "`n" senddata
NumPut(DllCall("Ws2_32\inet_addr", "Str", SubStr(senddata, 2, pos-2)), toaddr, 4, "UInt")
senddata:=SubStr(senddata, pos+1)
Guicontrol,, LogEdit, %log%
controlsend, edit1, ^{end}, Tiny UDP
}
Else
NumPut(0xFFFFFFFF, toaddr, 4, "UInt")
DllCall("Ws2_32\sendto", "UInt", sendsock, "Str", senddata, "UInt", StrLen(senddata), "UInt", 0x4, "UInt", &toaddr, "UInt", 32)
Guicontrol,, senddata,
return
; ----------------------------------------------------------------
#IfWinActive , Tiny UDP
up::
guicontrol,, senddata, %senddata%
return
down::
sendinput, /%a_IPAddress1%
return
enter::
gosub SendButton
return
; ----------------------------------------------------------------
GuiClose:
ExitSub:
NumPut(0xFFFFFFFF, toaddr, 4, "UInt")
DllCall("Ws2_32\sendto", "UInt", sendsock, "Str", "disconnected", "UInt", 12, "UInt", 0x4, "UInt", &toaddr, "UInt", 32)
DllCall("Ws2_32\WSACleanup")
ExitApp
However, I can't have web address... I have address of my router (X.X.X.254), anybody know how configure router or to have the real address ? ( peername on unconnected socket) or to have the header of source address in layer of UDP ( or it change with router ? )