Next: UNIXNetworkStreamReader, Previous: TCPIPV6NetworkStreamWriter, Up: Classes [Index]
UNIXNetworkStream
ClassUNIXNetworkStream
and its subclasses define instance and class
variables and methods to communicate over UNIX domain sockets between
processes and programs operating on the same machine.
As a type of interprocess communication, UNIX domain sockets are more flexible than named pipes - programs create and manage one or more sets of reader and writer objects independently of each other.
The section UNIXNetworkStreamReader describes the methods and instance data for creating and managing reader objects See UNIXNetworkStreamReader, and the section UNIXNetworkStreamWriter describes the details of writer objects See UNIXNetworkStreamWriter.
socketPrefix
A String
that defaults to the machine-specific directory
name where the system stores its temporary files (e.g.,
/tmp
, /var/tmp
, etc.).
sock
An Integer
that contains the file handle number the receiver’s
socket.
socketBaseName
A String
that contains the base name of the socket’s path
name. The string may contain escape characters. Refer to the
makeSocketPath
method, below.
socketPath
A String
that contains the fully qualified path name of
a program’s UNIX domain socket.
closeSocket
(void
)
Shuts down the receiver’s socket (defined in the sock
instance
variable) and deletes the socket’s file entry (which is defined in the
socketPath
instance variable), if present.
makeSocketPath
(String
basename)
Constructs a fully qualified socket path from basename and
the prefix given by socketPrefix
(described above).
If basename contains the characters ‘$$’, the method
replaces the character with the program’s process ID.
After constructing the fully qualified name, the method
fills in the receiver’s socketBaseName
and
socketPath
instance variables, and returns
the value of the socketPath
instance variable.
The small program here constructs and prints the file pathname of a program’s UNIX socket, which includes the process ID of the program.
int main () { UNIXNetworkStream new un; String new sockName; sockName = "myprogsocket.$$"; un makeSocketPath sockName; printf ("%s\n", un socketPath); }
removeSocket
(void
)
Deletes the socket’s file entry by its name, which is defined by
makeSocketPath
, above.
Next: UNIXNetworkStreamReader, Previous: TCPIPV6NetworkStreamWriter, Up: Classes [Index]