A network communications channel.
![]() | Socket establishment functions |
![]() | Socket options functions |
![]() | Port/Service database functions |
![]() | Multiple socket selection functions |
![]() | Integer conversion functions |
![]() | port Port to be used by the socket when opening the channel. |
![]() | GetProtocolName () const This function returns the protocol name for the socket type |
Construction
Overrides from class PObject
Information functions
Reading functions
Writing functions
Miscellaneous functions
Error functions
Run Time Type functions
Comparison functions
I/O functions
A network communications channel. This is based on the concepts in the Berkley Sockets library.A socket represents a bidirectional communications channel to a
port at a remotehost .
If the port parameter is zero then the port number as
defined by the object instance construction or the descendent classes
SetPort() or SetService() function.
The port that the socket uses is the one used in the Listen()
command of the socket parameter. Note an error occurs if
the socket parameter has not had the Listen()
function called on it. Note that this function will block until a remote system connects to the
port number specified in the "listening" socket. The time that the
function will block is determined by the read timeout of the
socket parameter. This will normally be
PMaxTimeInterval which indicates an infinite time. The default behaviour is to assert.
enum Reusability
virtual BOOL Listen( unsigned queueSize = 5, WORD port = 0, Reusability reuse = AddressIsExclusive )
port - Port number to use for the connection.
reuse - Can/Cant listen more than once.virtual BOOL Accept( PSocket & socket )
virtual BOOL Shutdown( ShutdownValue option )
BOOL SetOption( int option, const void * valuePtr, PINDEX valueSize, int level = SOL_SOCKET )
valuePtr - Pointer to new value for option.
valueSize - Size of new value.
level - Level for optionBOOL GetOption( int option, int & value, int level = SOL_SOCKET )
value - Integer to receive value.
level - Level for optionBOOL GetOption( int option, void * valuePtr, PINDEX valueSize, int level = SOL_SOCKET )
valuePtr - Pointer to buffer for value.
valueSize - Size of buffer to receive value.
level - Level for option
A name is a unique string contained in a system database. The parameter
here may be either this unique name, an integer value or both separated
by a space (name then integer). In the latter case the integer value is
used if the name cannot be found in the database. The exact behviour of this function is dependent on whether TCP or UDP
transport is being used. The PTCPSocket and PUDPSocket
classes will implement this function. The static version of the function is independent of the socket type as
its first parameter may be "tcp" or üdp",
A service name is a unique string contained in a system database. The
parameter here may be either this unique name, an integer value or both
separated by a space (name then integer). In the latter case the
integer value is used if the name cannot be found in the database. The exact behviour of this function is dependent on whether TCP or UDP
transport is being used. The PTCPSocket and PUDPSocket
classes will implement this function. The static version of the function is independent of the socket type as
its first parameter may be "tcp" or üdp",
A service name is a unique string contained in a system database. The
parameter here may be either this unique name, an integer value or both
separated by a space (name then integer). In the latter case the
integer value is used if the name cannot be found in the database. The port number may not be changed while the port is open and the
function will assert if an attempt is made to do so.
static PString GetNameByProtocol( WORD proto )
virtual WORD GetPortByService( const PString & service ) const
static WORD GetPortByService( const char * protocol, const PString & service )
service - Name of service to get port number for.virtual PString GetServiceByPort( WORD port ) const
static PString GetServiceByPort( const char * protocol, WORD port )
port - Number for service to find name of.void SetPort( WORD port )
void SetPort( const PString & service )
WORD GetPort() const
PString GetService() const
The read, write and
are modified by the call so that only the sockets that have data
available are present. If the call timed out then all of these lists
will be empty. If no timeout is specified then the call will block until a socket
has data available.
static int Select( PSocket & sock1, PSocket & sock2, const PTimeInterval & timeout )
sock2 - Second socket to check for readability.
timeout - Timeout for wait on read/write data.static Errors Select( SelectList & read )
static Errors Select( SelectList & read, const PTimeInterval & timeout )
timeout - Timeout for wait on read/write data.static Errors Select( SelectList & read, SelectList & write )
write - List of sockets to check for writability.static Errors Select( SelectList & read, SelectList & write, const PTimeInterval & timeout )
write - List of sockets to check for writability.
timeout - Timeout for wait on read/write data.static Errors Select( SelectList & read, SelectList & write, SelectList & except )
write - List of sockets to check for writability.
except - List of sockets to check for exceptions.static Errors Select( SelectList & read, SelectList & write, SelectList & except, const PTimeInterval & timeout )
write - List of sockets to check for writability.
except - List of sockets to check for exceptions.
timeout - Timeout for wait on read/write data.
inline static DWORD Host2Net(DWORD v)
inline static WORD Net2Host(WORD v)
inline static DWORD Net2Host(DWORD v)
WORD port
Alphabetic index HTML hierarchy of classes or Java