With the IPCSocket connection(on Mac) example, it seems that only 2 connections could communicate as a server and client.
I’m considering to keep multiple slaves(through console app) for communicating with Server through IPCSockets.
Is there any way to keep multiple IPCSockets connections from Server to many slave console apps?
Array of IPCSockets?
Yes, an array of sockets would be the way to go. When creating helper apps, I usually spin up a socket on a particular path and then launch the helper app, giving it the path on the command line, so the two can easily link up.
Can you let me know how I can declare a array of IPCSockets? Seem to be very weird question.
I’m very new to Xojo.
Make a property inside the App class or within a module (because you want these to persist) and name it something like:
mySockets() as IPCSocket
Then whenever you need a new one, create it and then append it to the array:
You’ll also want to create some cleanup code so that when a socket stops you can either start it listening again, or remove it from the array.
Thank you for the detail information.
I think it should look something like below.
Dim newsockets As IPCSocket
newsockets = New IPCSocket
mysockets(0).Path = SpecialFolder.Temporary.Child(“com.example.ipcsocketexample”).NativePath
From IPCSocket example, there is a IPCSocket control named CommSocket.
And, we can use several events such as Connected and Dataavailable…
With your approach, should I make a code like below to simulate the events above?
If mysockets(0).BytesAvailable Then
The path needs to be unique for each connection, so you want something more like:
for i as integer = 1 to NumberOfChildApps
mysockets(i).Path = SpecialFolder.Temporary.Child("com.example.ipcsocketexample").NativePath + str(i)
Also, if you re-use an existing path (from an app that crashed) you will get a 105 error when trying to re-use it. In that case you should have code to .Close the socket then try again.
This is a conversation I have been looking for for a while and am trying to wrap my ahead. I have 7 console applications that access a db with multiple schemas and tables and can do that in their own time depending on outside sources.
Now that the db has grown the value modifications in the db are at times incorrect and that is because the console apps access the db in similar times, grab the data and modify as they need to. However before they write their data the referenced information is now changed but not known by that particular console app and creates db data integrity problems
It is time to implement Inner Process Communications to ensure db data integrity on a per console application basis. I am trying to envision how to implement IPC with multiple console apps. The arrayed aspect appears to be what I need but after several attempts that did not work it appears there needs to be a Master and others act as slaves. Then is that is accurate how to implement an array of IPC sockets and enable full IPC communications without sacrificing the speed these apps have as console apps is needed.
So if any of this makes sense I am looking to get me head wrapped around this to be able to implement multiple IPC communications and enable db data integrity
Does any of this make sense and how to proceed
[quote=198351:@Carl Fitzsimmons]<…> However before they write their data the referenced information is now changed but not known by that particular console app and creates db data integrity problems
I think you would have to deal with this issue just like with any other multiuser database: you need a timestamp per record, to keep track of last modification time.
The console apps need to retrieve this timestamp and upon saving, it will only update if the timestamp is still the same. Otherwise it would have to retrieve the data again and restart its task from scratch.
Use transactions and/or triggers to accomplish this.
Interesting. I did not occur to me to implement such a strategy. While I am still interested in the IPC aspect this makes sense to apply such a strategy. Lets see what happens. Thanks
Or lock the record being edited?
Have a look at http://vladmihalcea.com/2014/09/14/a-beginners-guide-to-database-locking-and-the-lost-update-phenomena/
[quote]@Marcus Winter That is a good read as well and will look at Vlad next article.[/quote] Between IPC, time stamp, record locking and potentially optimistic locking the solution exists.
Ok - here goes
7 console apps are set to ‘Listen’ using the same global scoped strings
One global scope string per console app
All 7 are defined in the ‘CONNECT’ console app
Inside each console app ‘Listen’ or ‘Connect’ I placed these globals:
[quote]‘myIPCsocket’ with Super = ‘IPCsocket’ and defined all 3 Event Handlers ‘Connected’, ‘DataAvailable’ , ‘Error’
newsockets defined as type myIPCsocket
mySockets() with Type myIPCsocket
I created 7 IPCsockets using the following inside the Run event of APP
When I start up all ‘Listen’ console apps then I start the ‘Connect’ console app all is good. Things work as I would expect.
Doing some testing I quite the ‘Connect’ console app and restarted. Then the ‘Error’ event in myIPCsocket throws 103 which means it cannot resolve the hostname
[code] Dim x As Integer
For x = 0 to 6
newsockets = New myIPCsocket
'This is where the separate IPCSocket folders are defined using global strings myIPCSocket_folder1...7
Select Case x
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder1).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder2).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder3).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder4).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder5).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder6).NativePath
mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder7).NativePath
Any thoughts on how to resolve the 103 and or whats causing the error?
When you quit the connect app, all the listeners must detect that and start listening again. Otherwise, there’s nothing to connect to when the connect app restarts.
Tim - I just implemented reconnect as ‘Listen’ in the Error Handler 102 (lost connection) of one module and that appears to be the solution
Thanks for the insight. Now onto the rest of them