Hi there… I was wondering whether there was a way to pass values between 2 xojo applications…
If I had a helper program running and my main app… is there a way to communicate to the helper app to give it values and trigger events?
I suppose that I could do it via text files - but if there’s a more direct way, then that would be awesome!
Cool - I’ll do a help search on it!
There is an example in the communication folder.
I use easyTCPsocket if it only 2 programs talking to each other
They are very “easy” to set up and use.
If you need more of a group of programs then try easyUDPsocket, once you get your head around them they are easy as well.
I’ve got it working more or less…
Question… How do I send data one after another…
with it becoming one long string? Flush isn’t doing it. As you can see, I send 2 bits if info. the number tells the listening app what to do and the second bit is a value or a folder native path. when I do something like the above, the listener reads it like a long string. How do I send these separately without them being joined together?
You cannot control what arrives in a given “packet”. Each DataAvailable event could have a single message, several messages, part of a message, etc. You must impose some kind of protocol or format so the receiving end can make sense of what you’re sending. Minimally use a separator, such as Tab or EndOfLine, to mark the end of a message.
Suggestion: Use JSONItems to send messages through IPC. You can put structured data in a single string and JSON does all the parsing for you.
Suggestion 2: Wrap the JSON string in header and footer like START___JSONmessage___END and add a simple CRC like MSG_START___JSONMessage___CRC___MSG_END
Can easily do CRC with EncodeHex(md5(JSONMessage)), maybe there’s an even nicer way.
here’s a function I use on data I receive on IPC socket to check CRC, might be helpful. Here I do assume that a DataAvailable event gives me all the data on one shot, though. It’s not entirely right but works for me. If you do a Flush and then app.doevents(20) it seems to help flush to socket.
Function Message_IntegrityCheck(Message as String) As Boolean
dim StartEndPass, HashPass as Boolean
dim tMessage, tMessageHash, tStartString, tEndString as String
tStartString = NthField(Message, “",1)
tMessage = NthField(Message, "”,2)
tMessageHash = NthField(Message, “",3)
tEndString = NthField(Message, "”,4)
if tStartString = “MSG_START” and tEndString = “MSG_END” then ’ this is a valid packet if the START and END strings are in the right place
StartEndPass = True
’ Now check the hash
dim tMessageHash2 as String
tMessageHash2 = EncodeHex(md5(tMessage)) 'md5 hash of message
if tMessageHash2 = tMessageHash then
HashPass = True
if StartEndPass and HashPass then
Poll would be better, as it only affects the one socket.
How do you use Poll for the socket?
I do a Flush and app.doevents(20) on the socket that’s Sending right after a Write. On the Receiving socket, DataAvailable fires almost instantly and a .ReadAll seems to contain all the sent data in one shot, without any periodic poll.
The right way would probably be to establish some sort of framing if data was fragmented between DataAvailable events, but for low rate messages it works just fine… I have about 50 IPC messages per second between multiple apps and very rarely see a corrupt message.
Doevents is basically polling the socket for you, as well as doing a bunch of other stuff that you may not want happening.