IPCSocket Class

Used for interprocess communication between two applications on the same computer. Use TCPSocket for interprocess communication between applications on different computers.

Events

Connected

DataAvailable

Error


Properties

BytesAvailable

BytesLeftToSend

Handle

IsConnected

LastErrorCode

Path


Methods

Close

Connect

Listen

Poll

Read

ReadAll

Write


More information available in parent classes: Object


Class Constants

These constants indicate which error occurred. To determine which error occurred, compare the value of LastErrorCode to these constants. They are the same error codes returned by SocketCore.

Error CodeClass Constant
100 OpenDriverError
102 LostConnection
103 NameResolutionError
105 AddressInUseError
106 InvalidStateError
107 InvalidPortError
108 OutOfMemoryError


Notes

To set up interprocess communications, you first specify the path to the application that you wish to communicate with. This path is a Unix style path to a directory that you have write access to, followed by a the name for your socket. The name and path are completely arbitrary, but typically (and for maximum compatibility) you should use /tmp/myAppName or /var/tmp/myAppName.

You then try to connect your socket to an application. If there's already an instance of your application running on this machine, then you will connect to the other instance. However, if there are no other instances of this application running, then you will get a 103 error in the LastErrorCode property. In the example, the code will then attempt to listen, so the next instance of the application can connect to this one.

The example ensures that when you launch two instances of your application, they will automatically connect to one another. You can see this connection by placing a MsgBox in the Connected event.

When the connection is established, the IPCSocket will work like a regular TCPSocket When you want to terminate the connection, you call the Close method and the connection will be terminated.

The IPCSocket class implements the Readable and Writeable class interfaces. If you implement either or both of these interfaces, you must provide the methods specified by those class interfaces.

For more information about class interfaces and how to implement them, see the section "Class Interfaces" on page 440 of the User's Guide.


Example

The following example establishes communications with another copy of the application. It is in the Open event of a window. The IPCSocket referred to in the code was added to the window by choosing Add . IPCSocket from the window's contextual menu.

' Pick the path that the IPCSocket should use.
IPCSocket1.Path = "/tmp/myAwesomeApplication"
  
' Let's see if we can connect to an application already
' on this path.  If we can, then cool.
IPCSocket1.Connect
While True
 ' the socket
 IPCSocket1 .Poll
    
 ' Check to see if we're connected, or if
 ' there is an error
 If IPCSocket1.IsConnected or IPCSocket1.LastErrorCode <> 0 then
  Exit
 end
    
 ' Update the user interface
  App.DoEvents
wend
  
  ' Check to see why we exited the loop.
If IPCSocket1.LastErrorCode = IPCSocket1.NameResolutionError then
 ' It's because no one else was listening, so let's
 ' just start listening.
 IPCSocket1.Listen
End

See Also

SocketCore, TCPSocket classes.