UDP between apps?

Greetings -

I’ve been trying to set up communications between two apps on the same machine. I started with IPC but ran into problems with only one listener allowed (Re: Norman). And, there are also problems if one of the applications is terminated or one starts when the other is not running.

So, looking for an alternative, UDP seems like the next reasonable possibility. But, all of the documentation refers to applications running on different machines. Its not clear to me whether you can have two applications on one machine bound to the same port. If you can, what IP address would you use, localhost or something else?

In lieu of clear answers to those questions, other suggestions (about this problem) are welcome!

Many thanks
Jim Wagner
Oregon Research Electronics
Bio & Eco Engineering, Oregon State University

I’m not much into networking but what if you use two different ports for sending and receiving? App 1 sends to port xxx and listens to yyy, app2 sends to yyy and listens to xxx?
Another approach could be writing and reading a file. With modern machines there should be no measurable delay. App1 writes a file to a designated directory, app2 polls that directory with short interval. When using an XML file you should be able to pass all sorts of information.

Only one port is necessary. Just determine who listens first (server) and who talks first (client) then you can reverse rolls.

Can both listen?
What happens if both try to talk at the same time? Socket error?


And, would you use localhost or something else?


Many apps can be listening at the same time on a broadcast channel. I’ll send you an example. In the end though someone has to say so something and they may have to say it more than once. Because udp isn’t connection oriented there is no guarantee that anyone is listening. Discovery protocols like up no use the notion that there is a service provider listening for requests. Someone comes to life and says, “Is there anybody out there?” . Then one or more services may reply.

I’m away for my code for a little while. I’ll post an example for you in an hour or so.

Thanks, Brian -

I really do appreciate your help!


Here you go James
This is a UDP loopback test.
To use this on more than one machine simply get rid of the line send to self and set the destination IP address to the remote system’s up address.

UDP Loopback test

[quote=70389:@James Wagner]
I’ve been trying to set up communications between two apps on the same machine. I started with IPC but ran into problems with only one listener allowed (Re: Norman). [/quote]
Ummm I think I might be misunderstood
Have each try to listen when they start
One will work one will fail - the one that fails should just try to connect - and it should be able to since the other is listening
When / if one or both disconnect & get a failure do the same thing as again one will manage to successfully listen and the other won’t

Thanks, Brian and Thanks, Norman.

Norman, I have the situation where only one of the two apps is running and I set its IPCSocket to listen and it returns an error 106 (Invalid state, I think). I really want one (the “slave” in the pair) to sit there and listen for a commend from the “host”, even if the host has been terminated. If it cannot do this then how can the slave know to activate it’s IPCSocket (xplat) the next time the host becomes active?


I see your issue now. Sorry I should have read the original post better. You have two applications on the same machine.
Indeed you will have to bind on two separate ports.
Would you like me to show you how?
Did you try my example?

Brian - Got the example running. Works nice!

I was just adding the code to the two apps.

Suggestions on dealing with two ports would REALLY be appreciated.


Open two instances of this app on your computer. Once both are open, with the pull down select either master or slave.
(On mac os x you would have to do this from the terminal for the second instance by navigating to the app path and saying open -n name of applicaiton)

UDP Master Slave Test

Wow, that is a great example. And, more work from you than I expected.

Your help has made a huge difference!

Won’t be able to run this on compiled apps for several hours as this is debug-only platform at the university.

It would be great if these got included in the demo apps. Could REALLY help others!


It was very little work. Xojo makes these types of Applications so easy.
It is the reason I chose this as a development environment.
Stuff like this is a snap.

There is a wonderful UDP example in the demos but like most demos it isn’t exactly what you want.


I work with Xojo for exactly that reason. But, every once in a while, something throws me.

I looked hard at that example, and got very little out of it. With yours in hand, that makes a lot more sense.


Hello, Brian -

I have been using your template, but with two sockets, one for application A->B communication and one for B->A communication so that It is not necessary to switch ports. The first thing that I tried was both apps connecting to both ports. The second starter always shows error 106, Address in Use.

So, I changed it so that only the talker on each port connects. The documentation is not clear on which is proper. However, it does tell me that both applications are seeing the ports used by the companion.

I patterned the write and read operations after your demo but I am not getting anything. No errors, no nothing. I don’t see anything else that you do. There does not appear to be a flush method. Nor a listen method.

I realize that this is pretty sketchy. Any hints? The two socket approach seems to be the one difference from your example. If you would like, I can send you the two “apps”. They are still pretty primitive (and small).


Drop the project(s) in a DropBox and I’ll have a look. :slight_smile:

I just got it. I had the ports incorrectly paired.

Thanks for your help!


Confused now about ports and the various assignments. At this point, I have ONLY one UDPSocket in each application.

In the master, in the open event, I have

UDPSocket1.Port = 8080

And, in the master, when I send a message (push button action event), I have
dim d as new Datagram
d.Address = “”
d.Port = 8081
d.Data = “Hello”
UDPSocket1.Write d

In the slave, open event, I have

UDPSocket1.Port = 8081

Messages are being received BUT
The data available event of UDPSocket1 shows that the slave is hearing the message on port 8080… Should not the d.Port statement in the master cause it to be sent on 8081? UDPSocket1 in the slave is never told to do anything with 8080!

I am confused!