I have two programs - a web app and a desktop app. Both may be running on the same machine. One may be running and the other may not be. Impossible to know.
When both programs are running, I want to use IPC to communicate between the two programs. So I have an IPC socket that first attempts to connect to the IPCSocket file. If I get an error, then I know that the other app isn’t running and I set the IPCsocket to listen so that if the second app comes up, they can then connect and off we go.
That had been working until recently. I noticed communication was not happening between my apps. As I started to look into this, it now appears that I can’t just do what I’ve been doing. I don’t know if it is a change in Xojo, in the computer OS or both. All I know is what did work now doesn’t. In MacOS, I am getting an error code of 22 which appears to be an invalid argument error.
Once the connection fails, any attempt to then make the socket listen simply don’t work.
Do I need to re-create the socket? Why doesn’t what I am doing work?
[quote=356262:@Norman Palardy]Did you update your computers OS recently ?
Did it stop working then ?[/quote]
I don’t know when it stopped working. However, I did update to High Sierra and now it doesn’t work. So they might be related.
So I did some further testing. I took the IPC example project and in the error event I put the following code for testing:
Sub Error() Handles Error
MessageList.AddRow("Error: " + Str( Me.LastErrorCode ))
Dim err as Integer = me.LastErrorCode
If me.LastErrorCode <> 0 Then
me.Listen
End If
End Sub
So if I start the app in the debugger and with no other instance of the app running, click the “connect” button, I get error code 103 the firs time the error event happens - this is what I should get. Then I set the socket to Listen. However, after that I get error code 22 raised over and over and over again until a stack overflow occurs.
In Windows, this does not happen as I tried it there too. Not sure about Linux.
OK. I think I’ve found the solution to the problem. If I call Close on the IPCSocket before calling Listen in the error event, it works fine:
Sub Error() Handles Error
MessageList.AddRow("Error: " + Str( Me.LastErrorCode ))
Dim err as Integer = me.LastErrorCode
If me.LastErrorCode <> 0 Then
me.close
me.Listen
End If
End Sub