UDPStartup()
$hWs2_32 = DllOpen("ws2_32.dll")
$hSocket = _WinsockCreateSocket(2, 2, 17)
_WinsockBind($hSocket, "192.168.0.241", 88); The source address and port for the Socket. The IP must be your LAN IP. I've found that 127.0.0.1 does not work.
_WinsockConnect($hSocket, "192.168.0.64", 5060); The destination IP and port.
_WinsockSend($hSocket, "SEND MSG!")
Func _WinsockCreateSocket($Address_Family, $Socket_Type, $Protocol)
$iRet = DllCall($hWs2_32, "int", "socket", "int", $Address_Family, "int", $Socket_Type, "int", $Protocol)
Return $iRet[0]
EndFunc
Func _WinsockBind($hSocket, $IP, $Port)
$hAddr = _SocketAddr($IP, $Port)
$iRet = DllCall($hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($hAddr), "int", DllStructGetSize($hAddr))
Return $iRet[0]
EndFunc
Func _WinsockConnect($hSocket, $IP, $Port)
$hAddr = _SocketAddr($IP, $Port)
$iRet = DllCall($hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($hAddr), "int", DllStructGetSize($hAddr))
EndFunc
Func _WinsockSend($hSocket, $data)
$hBuf = DllStructCreate("byte[" & BinaryLen($data) & "]")
DllStructSetData($hBuf, 1, $data)
$iRet = DllCall($hWs2_32, "int", "send", "uint", $hSocket, "ptr", DllStructGetPtr($hBuf), "int", DllStructGetSize($hBuf), "int", 0)
If IsArray($iRet) Then _ArrayDisplay($iRet)
EndFunc
Func _SocketAddr($IP, $Port, $Address_Family = 2)
$stAddress = DllStructCreate("short; ushort; uint; char[8]")
DllStructSetData($stAddress, 1, $Address_Family)
$iRet = DllCall($hWs2_32, "ushort", "htons", "ushort", $Port)
DllStructSetData($stAddress, 2, $iRet[0])
$iRet = DllCall($hWs2_32, "uint", "inet_addr", "str", $IP)
DllStructSetData($stAddress, 3, $iRet[0])
Return $stAddress
EndFunc ;==>_SocketAddr
Func _WSAGetLastError()
$iRet = DllCall($hWs2_32, "int", "WSAGetLastError")
Return $iRet[0]
EndFunc ;==>_WSAGetLastError