NTcpSocket Class Reference

NTcpSocket provides an easy interface to manipulate TCP Sockets. More...

Inheritance diagram for NTcpSocket:

NAbstractSocket NAbstractSocket NIODevice NIODevice NObject NObject

List of all members.

Public Member Functions

 NTcpSocket (void)
 Creates a NTcpSocket object.
 NTcpSocket (NHostAddress &host)
 Creates a NTcpSocket object.
 NTcpSocket (const NString &host, nuint16 port)
 Creates a NTcpSocket object.
 ~NTcpSocket (void)
 Destroys a NTcpSocket object.
void setPort (nint16 port)
 Sets the port associated with the socket.
void setSocketOptions (nint32 opt)
 Sets socket options.
NHostAddress peerAddress (void) const
 Gets the address of the remote host.
NString peerName (void) const
 Gets the name of the remote host.
nuint16 peerPort (void) const
 Gets the port of the remote host.
void open (void)
 Open the socket.
void closeDevice (void)
 Closes the socket.
void disconnectFromHost (void)
 Disconnects from the remote host.
void connectToHost ()
 Connects to a host.
void execListen (void)
 Starts listening.
NTcpSocketwaitForConnected (void)
 Waits until a connection occurs.
nint32 read (NDataStream *buffer)
 Reads data from the socket.
nint32 read (NDataStream *buffer, nuint32 bytes=0)
 Reads data from the socket.
nint32 readLine (NDataStream *buffer)
 Reads a line from the socket.
nint32 write (const NDataStream &data, nuint32 bytes=0)
 Writes data to the socket.
nint32 writeLine (const NDataStream &data, nuint32 bytes=0)
 Writes a line of data to the socket.
 NTcpSocket (void)
 Creates a NTcpSocket object.
 NTcpSocket (NHostAddress &host)
 Creates a NTcpSocket object.
 NTcpSocket (const NString &host, nuint16 port)
 Creates a NTcpSocket object.
 ~NTcpSocket (void)
 Destroys a NTcpSocket object.
void setPort (nint16 port)
 Sets the port associated with the socket.
void setSocketOptions (nint32 opt)
 Sets socket options.
NHostAddress peerAddress (void) const
 Gets the address of the remote host.
NString peerName (void) const
 Gets the name of the remote host.
nuint16 peerPort (void) const
 Gets the port of the remote host.
void open (void)
 Open the socket.
void closeDevice (void)
 Closes the socket.
void disconnectFromHost (void)
 Disconnects from the remote host.
void connectToHost ()
 Connects to a host.
void execListen (void)
 Starts listening.
NTcpSocketwaitForConnected (void)
 Waits until a connection occurs.
nint32 read (NDataStream *buffer)
 Reads data from the socket.
nint32 read (NDataStream *buffer, nuint32 bytes)
 Reads data from the socket.
nint32 readLine (NDataStream *buffer)
 Reads a line from the socket.
nint32 write (const NDataStream &data, nuint32 bytes=0)
 Writes data to the socket.
nint32 writeLine (const NDataStream &data, nuint32 bytes=0)
 Writes a line of data to the socket.


Detailed Description

NTcpSocket provides an easy interface to manipulate TCP Sockets.

Note:
For details see NAbstractSocket
Examples:

clientapp.cpp.

Definition at line 50 of file linux/ntcpsocket.h.


Constructor & Destructor Documentation

NTcpSocket ( NHostAddress host  ) 

Creates a NTcpSocket object.

Parameters:
host Hostname/ip associated with the socket

Definition at line 32 of file linux/ntcpsocket.cpp.

NTcpSocket ( const NString host,
nuint16  port 
)

Creates a NTcpSocket object.

Parameters:
host Hostname/ip associated with the socket
port Port associated with the socket

Definition at line 41 of file linux/ntcpsocket.cpp.

NTcpSocket ( NHostAddress host  ) 

Creates a NTcpSocket object.

Parameters:
host Hostname/ip associated with the socket

NTcpSocket ( const NString host,
nuint16  port 
)

Creates a NTcpSocket object.

Parameters:
host Hostname/ip associated with the socket
port Port associated with the socket


Member Function Documentation

void setPort ( nint16  port  ) 

Sets the port associated with the socket.

Parameters:
port The port number associated with the socket

Definition at line 66 of file linux/ntcpsocket.cpp.

References NAbstractSocket::m_port, and NAbstractSocket::setPort().

NHostAddress peerAddress ( void   )  const

Gets the address of the remote host.

Returns:
The address of the remote host

Definition at line 218 of file linux/ntcpsocket.cpp.

References NHostAddress::setAddress().

Referenced by peerName().

NString peerName ( void   )  const

Gets the name of the remote host.

Returns:
The name of the remote host

Definition at line 226 of file linux/ntcpsocket.cpp.

References peerAddress(), and NHostAddress::toString().

nuint16 peerPort ( void   )  const

Gets the port of the remote host.

Returns:
The port of the remote host

Definition at line 231 of file linux/ntcpsocket.cpp.

NTcpSocket * waitForConnected ( void   ) 

Waits until a connection occurs.

Returns:
A pointer to a NTcpSocket object associated with the newly created connection
Examples:
clientapp.cpp.

Definition at line 194 of file linux/ntcpsocket.cpp.

References NAbstractSocket::m_host, NAbstractSocket::m_port, NAbstractSocket::m_timeout, NException::NETWORK, NSTR(), NTcpSocket(), NString::number(), NNetworkException::SOCKET_INIT_FAILED, and NHostAddress::toString().

nint32 read ( NDataStream buffer  )  [virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NAbstractSocket.

Definition at line 236 of file linux/ntcpsocket.cpp.

References NDataStream::append(), NAbstractSocket::m_host, NIODevice::m_readBufferSize, NAbstractSocket::m_timeout, NException::NETWORK, NNetworkException::SOCK_ERROR, and NHostAddress::toString().

nint32 read ( NDataStream buffer,
nuint32  bytes = 0 
) [virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
bytes Max number of bytes to read
Returns:
The number of bytes read

Implements NAbstractSocket.

Definition at line 288 of file linux/ntcpsocket.cpp.

References NDataStream::append(), NAbstractSocket::m_host, NAbstractSocket::m_timeout, NException::NETWORK, NNetworkException::SOCK_ERROR, and NHostAddress::toString().

nint32 readLine ( NDataStream buffer  )  [virtual]

Reads a line from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NAbstractSocket.

Examples:
clientapp.cpp.

Definition at line 341 of file linux/ntcpsocket.cpp.

References NDataStream::append(), NAbstractSocket::m_host, NAbstractSocket::m_timeout, NException::NETWORK, NDebug::print(), NNetworkException::SOCK_ERROR, and NHostAddress::toString().

nint32 write ( const NDataStream data,
nuint32  bytes = 0 
) [virtual]

Writes data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written

Implements NAbstractSocket.

Examples:
clientapp.cpp.

Definition at line 399 of file linux/ntcpsocket.cpp.

References NDataStream::data(), and NDataStream::size().

nint32 writeLine ( const NDataStream data,
nuint32  bytes = 0 
) [virtual]

Writes a line of data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written
Note:
It's not needed to append a carriage return/line feed at the end of the data. The object will do that for you. If you don't want this behaviour, use write() instead.

Implements NAbstractSocket.

Examples:
clientapp.cpp.

Definition at line 408 of file linux/ntcpsocket.cpp.

References NDataStream::data(), and NDataStream::size().

void setPort ( nint16  port  ) 

Sets the port associated with the socket.

Parameters:
port The port number associated with the socket

NHostAddress peerAddress ( void   )  const

Gets the address of the remote host.

Returns:
The address of the remote host

NString peerName ( void   )  const

Gets the name of the remote host.

Returns:
The name of the remote host

nuint16 peerPort ( void   )  const

Gets the port of the remote host.

Returns:
The port of the remote host

NTcpSocket* waitForConnected ( void   ) 

Waits until a connection occurs.

Returns:
A pointer to a NTcpSocket object associated with the newly created connection

nint32 read ( NDataStream buffer  )  [virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NAbstractSocket.

nint32 read ( NDataStream buffer,
nuint32  bytes 
) [virtual]

Reads data from the socket.

Parameters:
buffer Buffer to save the received data
bytes Max number of bytes to read
Returns:
The number of bytes read

Implements NAbstractSocket.

nint32 readLine ( NDataStream buffer  )  [virtual]

Reads a line from the socket.

Parameters:
buffer Buffer to save the received data
Returns:
The number of bytes read

Implements NAbstractSocket.

nint32 write ( const NDataStream data,
nuint32  bytes = 0 
) [virtual]

Writes data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written

Implements NAbstractSocket.

nint32 writeLine ( const NDataStream data,
nuint32  bytes = 0 
) [virtual]

Writes a line of data to the socket.

Parameters:
data Data to be written to the socket
bytes Max number of bytes to write to the socket
Returns:
The amount of bytes written
Note:
It's not needed to append a carriage return/line feed at the end of the data. The object will do that for you. If you don't want this behaviour, use write() instead.

Implements NAbstractSocket.


The documentation for this class was generated from the following files:
Generated on Wed Mar 5 23:10:37 2008 for NemesisUtilitiesSystem by  doxygen 1.5.4