# How to keep multiple IPCSocket connection

**URL:** <https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322>\
**Category:** General\
**Created:** [March 30, 2015, 1:00pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322 "2015-03-30T13:00:40Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [March 30, 2015, 1:00pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/1 "2015-03-30T13:00:40Z")

</div>

Hi,  
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?

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [March 30, 2015, 1:07pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/2 "2015-03-30T13:07:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [March 30, 2015, 1:11pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/3 "2015-03-30T13:11:40Z")

</div>

Ok. Thanks.  
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.

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [March 30, 2015, 1:16pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/4 "2015-03-30T13:16:39Z")

</div>

Make a property inside the App class or within a module (because you want these to persist) and name it something like:

```auto
mySockets() as IPCSocket
```

Then whenever you need a new one, create it and then append it to the array:

```auto
mySockets.append newSocket
```

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.

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [March 30, 2015, 1:48pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/5 "2015-03-30T13:48:53Z")

</div>

Thank you for the detail information.

I think it should look something like below.

Dim newsockets As IPCSocket  
newsockets = New IPCSocket

mysockets.Append newsockets

mysockets(0).Path = SpecialFolder.Temporary.Child(“com.example.ipcsocketexample”).NativePath  
mysockets(0).Connect  
mysockets(0).Listen  
…

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  
…

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [April 1, 2015, 12:47am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/6 "2015-04-01T00:47:14Z")

</div>

The path needs to be unique for each connection, so you want something more like:

```auto
for i as integer = 1 to NumberOfChildApps
   mysockets(i).Path = SpecialFolder.Temporary.Child("com.example.ipcsocketexample").NativePath + str(i)
...
next
```

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.

---

<div class="post-metadata">

**Author:** ![changwon\_lee](https://forum.xojo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@changwon\_lee](https://forum.xojo.com/u/changwon_lee)\
**Post date:** [April 1, 2015, 1:26am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/7 "2015-04-01T01:26:06Z")

</div>

Great. Thank you!

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [April 1, 2015, 9:46am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/8 "2015-04-01T09:46:43Z")

</div>

[http://documentation.xojo.com/index.php/GetTemporaryFolderItem](http://documentation.xojo.com/index.php/GetTemporaryFolderItem) can be of use to create the path in a very simple way.

---

<div class="post-metadata">

**Author:** ![Carl\_Fitzsimmons](https://forum.xojo.com/user_avatar/forum.xojo.com/carl_fitzsimmons/32/15362_2.png) [@Carl\_Fitzsimmons](https://forum.xojo.com/u/Carl_Fitzsimmons)\
**Post date:** [July 2, 2015, 11:53pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/9 "2015-07-02T23:53:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Oliver\_Osswald](https://forum.xojo.com/user_avatar/forum.xojo.com/oliver_osswald/32/6972_2.png) [@Oliver\_Osswald](https://forum.xojo.com/u/Oliver_Osswald)\
**Post date:** [July 3, 2015, 3:44am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/10 "2015-07-03T03:44:01Z")

</div>

[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  
\<…\>[/quote]  
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.

---

<div class="post-metadata">

**Author:** ![Carl\_Fitzsimmons](https://forum.xojo.com/user_avatar/forum.xojo.com/carl_fitzsimmons/32/15362_2.png) [@Carl\_Fitzsimmons](https://forum.xojo.com/u/Carl_Fitzsimmons)\
**Post date:** [July 3, 2015, 12:23pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/11 "2015-07-03T12:23:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Markus\_Winter](https://forum.xojo.com/user_avatar/forum.xojo.com/markus_winter/32/144_2.png) [@Markus\_Winter](https://forum.xojo.com/u/Markus_Winter)\
**Post date:** [July 3, 2015, 12:55pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/12 "2015-07-03T12:55:17Z")

</div>

> [@198362:@Oliver Osswald](#):
>
> 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.

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/](http://vladmihalcea.com/2014/09/14/a-beginners-guide-to-database-locking-and-the-lost-update-phenomena/)

---

<div class="post-metadata">

**Author:** ![Carl\_Fitzsimmons](https://forum.xojo.com/user_avatar/forum.xojo.com/carl_fitzsimmons/32/15362_2.png) [@Carl\_Fitzsimmons](https://forum.xojo.com/u/Carl_Fitzsimmons)\
**Post date:** [July 3, 2015, 1:16pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/13 "2015-07-03T13:16:12Z")

</div>

[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.

---

<div class="post-metadata">

**Author:** ![Carl\_Fitzsimmons](https://forum.xojo.com/user_avatar/forum.xojo.com/carl_fitzsimmons/32/15362_2.png) [@Carl\_Fitzsimmons](https://forum.xojo.com/u/Carl_Fitzsimmons)\
**Post date:** [July 9, 2015, 1:01am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/14 "2015-07-09T01:01:40Z")

</div>

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

[quote]myIPCSocket\_folder1  
myIPCSocket\_folder2  
myIPCSocket\_folder3  
myIPCSocket\_folder4  
myIPCSocket\_folder5  
myIPCSocket\_folder6  
myIPCSocket\_folder7  
[/quote]

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  
[/quote]

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
mySockets.Append newsockets
    
'This is where the separate IPCSocket folders are defined using global strings myIPCSocket_folder1...7
Select Case x
Case 0
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder1).NativePath
Case 1
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder2).NativePath
Case 2
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder3).NativePath
Case 3
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder4).NativePath
Case 4
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder5).NativePath
Case 5
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder6).NativePath
Case 6
  mySockets(x).Path = SpecialFolder.Temporary.Child(myIPCSocket_folder7).NativePath
End

'Now connect
mysockets(x).Connect

```

Next  
[/code]

Any thoughts on how to resolve the 103 and or whats causing the error?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [July 9, 2015, 1:11am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/15 "2015-07-09T01:11:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Carl\_Fitzsimmons](https://forum.xojo.com/user_avatar/forum.xojo.com/carl_fitzsimmons/32/15362_2.png) [@Carl\_Fitzsimmons](https://forum.xojo.com/u/Carl_Fitzsimmons)\
**Post date:** [July 9, 2015, 1:57am UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/16 "2015-07-09T01:57:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:42pm UTC](https://forum.xojo.com/t/how-to-keep-multiple-ipcsocket-connection/23322/17 "2020-10-29T17:42:28Z")

</div>


