class PInternetProtocol |
A TCP/IP socket for process/application layer high level protocols.
![]() | Read ( void* buf, PINDEX len ) Low level read from the channel. |
![]() | Write ( const void* buf, PINDEX len ) Low level write to the channel. |
![]() | SetReadLineTimeout ( const PTimeInterval & t ) Set the maximum timeout between characters within a line. |
![]() | Connect ( const PString & address, WORD port = 0 ) Connect a socket to a remote host for the internet protocol. |
![]() | Accept ( PSocket & listener ) Accept a server socket to a remote host for the internet protocol. |
![]() | GetDefaultService () const Get the default service name or port number to use in socket connections. |
![]() | GetSocket () const Get the eventual socket for the series of indirect channels that may be between the current protocol and the actual I/O channel. |
![]() | WriteLine ( const PString & line ) Write a string to the socket channel followed by a CR/LF pair. |
![]() | ReadLine ( PString & line, BOOL allowContinuation = FALSE ) Read a string from the socket channel up to a CR/LF pair. |
![]() | UnRead ( int ch ) Put back the characters into the data stream so that the next <A>Read()</A> function call will return them first |
![]() | WriteCommand ( PINDEX cmdNumber ) Write a single line for a command. |
![]() | ReadCommand ( PINDEX & num, PString & args ) Read a single line of a command which ends with a CR/LF pair. |
![]() | WriteResponse ( unsigned numericCode, const PString & info ) Write a response code followed by a text string describing the response to a command. |
![]() | ReadResponse () Read a response code followed by a text string describing the response to a command. |
![]() | ExecuteCommand ( PINDEX cmdNumber ) Write a command to the socket, using <CODE>WriteCommand()</CODE> and await a response using <CODE>ReadResponse()</CODE>. |
![]() | GetLastResponseCode () const Return the code associated with the last response received by the socket. |
![]() | GetLastResponseInfo () const Return the last response received by the socket. |
![]() | ParseResponse ( const PString & line ) Parse a response line string into a response code and any extra info on the line. |
Construction
Overrides from class PObject
Overrides from class PChannel
Channel establish functions
Information functions
Reading functions
Writing functions
Miscellaneous functions
Error functions
Run Time Type functions
I/O functions
Comparison functions
A TCP/IP socket for process/application layer high level protocols. All of these protocols execute commands and responses in a standard manner.A command consists of a line starting with a short, case insensitive command string terminated by a space or the end of the line. This may be followed by optional arguments.
A response to a command is usually a number and/or a short string eg "OK". The response may be followed by additional information about the response but this is not typically used by the protocol. It is only for user information and may be tracked in log files etc.
All command and reponse lines of the protocol are terminated by a CR/LF pair. A command or response line may be followed by additional data as determined by the protocol, but this data is "outside" the protocol specification as defined by this class.
The default read timeout is to 10 minutes by the constructor.
This override also supports the mechanism in the <A>UnRead()</A> function allowing characters to be be "put back" into the data stream. This allows a look-ahead required by the logic of some protocols. This is completely independent of the standard iostream mechanisms which do not support the level of timeout control required by the protocols.
This override assures that the sequence CR/LF/./CR/LF does not occur by byte stuffing an extra '.' character into the data stream, whenever a line begins with a '.' character.
Note that this only occurs if the member variable <CODE>stuffingState</CODE> has been set to some value other than <CODE>DontStuff</CODE>, usually <CODE>StuffIdle</CODE>. Also, if the <CODE>newLineToCRLF</CODE> member variable is TRUE then all occurrences of a '\n' character will be translated to a CR/LF pair.
This will assert if the I/O channel is not an IP socket.
If the <CODE>unstuffLine</CODE> parameter is set then the function will remove the '.' character from the start of any line that begins with two consecutive '.' characters. A line that has is exclusively a '.' character will make the function return FALSE.
Note this function will block for the time specified by the <A>PChannel::SetReadTimeout()</A> function for only the first character in the line. The rest of the characters must each arrive within the time set by the <CODE>readLineTimeout</CODE> member variable. The timeout is set back to the original setting when the function returns.
If the <CODE>cmdNumber</CODE> parameter is outside of the range of valid command names, then the function does not send anything and returns FALSE.
This function is typically used by client forms of the socket.
If the command does not match any of the command names then the entire line is placed in the <CODE>args</CODE> parameter and a value of P_MAX_INDEX is returned.
Note this function will block for the time specified by the <A>PChannel::SetReadTimeout()</A> function.
This function is typically used by server forms of the socket.
If the <CODE>info</CODE> parameter has multiple lines then each line has the response code at the start. A '-' character separates the code from the text on all lines but the last where a ' ' character is used.
The first form assumes that the response code is a 3 digit numerical code. The second form allows for any arbitrary string to be the code.
This function is typically used by server forms of the socket.
The response may have multiple lines in it. A '-' character separates the code from the text on all lines but the last where a ' ' character is used. The <CODE>info</CODE> parameter will have placed in it all of the response lines separated by a single '\n' character.
The first form places the response code and info into the protected member variables <CODE>lastResponseCode</CODE> and <CODE>lastResponseInfo</CODE>.
This function is typically used by client forms of the socket.
This function is typically used by client forms of the socket.
The default bahaviour looks for a space or a '-' and splits the code and info either side of that character, then returns FALSE.
Alphabetic index HTML hierarchy of classes or Java