IPC Socket Q

Hi,

I have noticed on my test code the “connect” side will connect, I write data to my client without issue, but then I am noticing that on my Connect side it automatically closes the connection. ( giving me a Error 102 Connection terminated message). My problem is that I haven’t called then IPCSOCKET.Close yet and I would like to keep the IPCSocket open. Any ideas? This is basic code since I am trying to understand exactly how IPC Sockets function.

Any advice is majorly appreciated.

I am using RS 2012R1 still.

Connect side:

  InterAppCommunications = new  IPCInterCommunication
  InterAppCommunications.Path = SpecialFolder.UserHome.Child("IPC").ShellPath
  InterAppCommunications.Connect
  InterAppCommunications.poll

Receiving Side:

  InterAppCommunications = new  IPCInterCommunication
  InterAppCommunications.Path = SpecialFolder.UserHome.Child("IPC").ShellPath
  InterAppCommunications.Listen
  do
    InterAppCommunications.Poll
  loop until InterAppCommunications.BufferIsEmpty

logFile output:

2013-08-27 22:19:14   "Connect Side" Connected
2013-08-27 22:19:14   "Receiving Side" Connected
2013-08-27 22:19:14   "ConnectSide Buffer Write": 88888888;13;ae;123;23;
2013-08-27 22:19:14   "Connect Side:" IPC Code [102] Connection was terminated

Thanks in advance!

Is this in a console app? Otherwise, why the looping and polling?

The Receiving side is a console app and the connecting side is Desktop

is it possible your connect side IPCSocket is going out of scope and so disconnecting ?

What happens on the receiving side after BufferIsEmpty? Do you poll the socket again? Or create an event loop? Or does the socket just die?

The receiving side loops back to listening. The sending side sends the socket termination. Tim my sending side codes resides in a Sub method being called from a pushbutton event. I assume that when that Sub ends that is causing the socket to terminate with a 102 even though I am not closing it?

Norman that is probably what is happening. Using a pushbutton like I am what would be a good snippet to keep this from happening? I tried some loops but failed.

In my normal app I won’t be calling any IPC connections from pushbutton events, but this is how I built my test app :slight_smile:

Thanks!

If InterAppCommunications is a local variable, then that is indeed what is happening. If so, make it a property of the window so it stays alive after the button’s event.

InterAppCommunications already is a private property of the Window yes. On the Console app side it is the same but a private property of the app.

Something is funky though. I can pass data and connect using the IDE start just fine. I introduce a breakpoint on the sending side and it fails connection (103) everytime. I then remove the breakpoint and it works passing data again.

Disregard the IDE comment as I restarted and all is good there. I am still trying to see why the sending side is disconnecting still.

Watching the debug when it steps to the “end sub” after the poll it disconnects. (Sending side)

On the sending side, the poll shouldn’t be necessary. Are you sure you’re not dimming a variable with the same name in the button code?

I am positive I am not diming the variable locally… Just on the property. I did remove the poll and now I step through with the debugger and it shows true for connected after the “sub end”. Weird thing is that my error log still shows a disconnect 102 from the sending side InterAppCommunications IPC Socket class. That isn’t normal is it?

  // Error Check Control
  If me.LastErrorCode <> 0 then
    
    if me.LastErrorCode = 100 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + " There was an error opening and initializing the drivers.")
      
    elseif me.LastErrorCode = 102 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + " Connection was terminated")
      
    elseif me.LastErrorCode = 103 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + "  Unable to resolve hostname.")
      
    elseif me.LastErrorCode = 105 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + "  The IP Address currently is in use.")
      
    elseif me.LastErrorCode = 106 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + "  The Socket is in an invalid state.")
      
    elseif me.LastErrorCode = 107 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + "  The Port number specified is invalid]")
      
    elseif me.LastErrorCode = 108 then
      mLogFacility("Tombstone IPC Code[" + str(me.LastErrorCode)+"]" + "  Out of memory Error.")
      
    else
      mLogFacility("Tombstone IPC Error Code[" + str(me.LastErrorCode)+"]")
      Exit
    End If
  end if

Tim ok. I found it. I was causing myself a nil exception error on the console app side and missed it by not checking the terminal enough :slight_smile: You having me remove the poll from the sending side actually kept me from disconnecting. Thanks again Tim and Norman… I appreciate you taking the time with me the noobie :wink: