Sign in to follow this  
Followers 0
Threap

UDP multicast send and receive from the same program?

4 posts in this topic

Hello esteemed AutoIt experts,

I am using the UDP functions in AutoIt to try and multicast data, but I've quickly run into a problem ;)

Here's my aim.. to have a number of PCs on the same LAN subnet, each running an AutoIt program ("A"). At ANY time, ANY of those PCs might launch another program ("B") which will send a network signal to run a Windows application (e.g Notepad.exe). As long as each of our PCs are running that application, I want them to be signalling on the network; program "B" will only exit when it detects that it hasn't received such a signal for a period of, say, 3 seconds.

I started using UDP as the most promising technology for this. A complication is that I don't know the IP address of the recipient(s) - as long as they're on the same subnet, I want other PCs running program "A" to get the data.

There are other possible issues that I can see here:

-A and B are both "client" and "server" at different times, receiving and sending data. Does it matter that B starts up after A?

-if there are two tasks running on the same PC, both listening on the same port, do datagrams sent to that port get "swallowed" by the first app to parse them?

What I've done is essentially the same as the example UDP code in the AutoIt helpfile. Here's part of "A":

$socket = UDPBind($my_IP, $IP_Listen_Port)
If @error <> 0 Then Exit

Traytip("Info","Listening on " & $my_IP,10,16) ; just to let me know the program's started listening on the right IP interface

While 1
    $sReceived = UDPRecv($socket, 128)
    If $sReceived <> "" Then
        fReceived($sReceived) ; this is a function that analyses the received info and acts on it according to its contents!
                                      ; if it means launching a task then $Running_Task is set to the taskname, e.g notepad.exe
    EndIf
    sleep(200)

    If $Running_Task <> "" Then ; if we've previously received an instruction to launch a specific task, I want to keep sending "heartbeat" packets as long as that task's running
        UDPSend($socket, $my_IP & $cDelimiter & "RUNNING" & $cDelimiter & $Running_Task) 
        Sleep(500)
                If Not(ProcessExists($Running_Task)) Then $Running_Task = "" ; if the task's finished, then stop sending the keepalives.
    EndIf
WEnd

Program B (probably invoked AFTER the first one) contains this code:

While ($boolRunning)
    $sReceived = UDPRecv($socket, 128)
    If $sReceived <> "" Then ; something came in over UDP
        fReceived($sReceived) ; parse it - if it's a "RUNNING" message then peg $Timer back to a high value, so that this While/Wend loop keeps running.
        Msgbox(0,"debug","received",3) ; just for debug - and never pops up, hence my question here :(
    EndIf       
    Sleep(300)
    $Timer -= 1
    If $Timer < 0 Then $bRunning = False ; we haven't received a "still running" message in 3 seconds, so it's safe to quit.
Wend

The problem seems to be in the code snippet above - although the first program is (as far as I know) sending its data, the second program above never receives anything.

What am I doing wrong? These forums have never let me down in the past - here's hoping your collective mighty wisdom can set me straight once again! :)

Please let me know if I need to supply more details. Many, many thanks in advance.

Share this post


Link to post
Share on other sites



Hello esteemed AutoIt experts,

I am using the UDP functions in AutoIt to try and multicast data, but I've quickly run into a problem :)

Oh, come on.. does no-one have any suggestions? Please? I would really appreciate some guidance - I know helping people out on these forums is a tedious, thankless task but it would make a big difference to me to have some advice here.

Thanks!

Share this post


Link to post
Share on other sites

it's not best solution but try put 2 exe files in 1 using FileInstall()


edited

Share this post


Link to post
Share on other sites

Oh, come on.. does no-one have any suggestions? Please? I would really appreciate some guidance - I know helping people out on these forums is a tedious, thankless task but it would make a big difference to me to have some advice here.

Thanks!

My suggestion is to give us a script which we can actually run and see the problem. I know it's tedious ....


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0