Jump to content

Recommended Posts

Posted

Ive spent a few hours reading threads dating back years to do with udp multicast. none of them seem to have ever been resolved.

am i wasting my time trying to find a working solution to bind and use udp multicast addresses for example 239.xyz.xyz.xyz on a network to communicate to and from scripts on diferent computers using autoit?

its a real bummer if its not possible.

Posted

yeah i thought as much but i also thought if i did it from scratch myself it would be an endeavor of which the end would not be reached before the time i need something running unless its already been solved by someone.

Posted (edited)

I don't know if you meant this?
 

;--- Client ---

TCPStartup()

Local $sendstring = "Find_led"
ConsoleWrite(_get_server_ip($sendstring)


Func _get_server_ip($sendstring)
    Local $data, $count, $count_total
    UDPStartup()

    Local $socket_send = UDPOpen(StringRegExpReplace(@IPAddress1, "(\d+)$", "") & "255", 6666)
    Local $socket_recieve = UDPBind(@IPAddress1, 7777)

    If UDPSend($socket_send, $sendstring) = 0 then
        SetError(1);
    Else
        While 1
            If $count_total > 20 Then
                SetError(2)
                ExitLoop
            EndIf
            If $count > 5 Then
                If UDPSend($socket_send, $sendstring) = 0 then
                    SetError(1);
                    ExitLoop
                EndIf
                $count = 0
            EndIf
            $data = UDPRecv($socket_recieve, 50)
            If $data <> "" Then
                ExitLoop
            EndIf
            $count = $count + 1
            $count_total = $count_total + 1
            Sleep(100)
        WEnd
    EndIf

    UDPCloseSocket($socket_send)
    UDPCloseSocket($socket_recieve)
    UDPShutdown()

    Return $data
EndFunc


;--- Server ---

TCPStartup()
$socket_recieve = UDPBind(@IPAddress1, 6666)

While 1
    $data = UDPRecv($socket_recieve, 50)
    If $data <> "" Then
        If $data = "Find_led" Then
            $socket_send = UDPOpen("192.168.0.255", 7777)
            $status = UDPSend($socket_send, @IPAddress1)
            UDPCloseSocket($socket_send)
        EndIf
    EndIf
WEnd

This is a bit of code (of a much larger project) I used to get the ipadres of a server by UDP muliticast.
This is a piece of code and didn't test this pieces so it's possible it won't work correctly.

Edited by nend

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...