nidas
v1.2-1520
|
A stream (TCP) socket that is used to listen for connections. More...
#include <Socket.h>
Public Member Functions | |
ServerSocket (int port=0, int backlog=10) throw (IOException) | |
Create a AF_INET ServerSocket bound to a port on all local interfaces. More... | |
throw (IOException) | |
Create a ServerSocket bound to port on a given local address, and set listen backlog parameter. More... | |
throw (IOException) | |
Create a ServerSocket bound to an address, and set listen backlog parameter. More... | |
~ServerSocket () throw () | |
Destructor. More... | |
int | getFd () const |
void | close () throw (IOException) |
close the socket. More... | |
Socket * | accept () throw (IOException) |
Accept connection, return a connected Socket instance. More... | |
void | setReceiveBufferSize (int size) throw (IOException) |
int | getReceiveBufferSize () throw (IOException) |
void | setSendBufferSize (int size) throw (IOException) |
int | getSendBufferSize () throw (IOException) |
const SocketAddress & | getLocalSocketAddress () const throw () |
Fetch the local address that this socket is bound to. More... | |
int | getLocalPort () const throw () |
int | getDomain () const |
void | setNonBlocking (bool val) throw (IOException) |
bool | isNonBlocking () const throw (IOException) |
Protected Attributes | |
SocketImpl | _impl |
A stream (TCP) socket that is used to listen for connections.
This class is patterned after the java.net.ServerSocket class.
This class provides the public copy constructors and assignment operators. Objects of this class can be copied and assigned to without restriction. However, because of this, the destructor does not close the socket, so it is the user's responsibility to call Socket::close() when finished with the connection.
Usage scenario of a server which listens for connections on port 5000, and spawns a thread to handle each connection.
ServerSocket::ServerSocket | ( | int | port = 0 , |
int | backlog = 10 |
||
) | |||
throw | ( | IOException | |
) |
Create a AF_INET ServerSocket bound to a port on all local interfaces.
port | Port number, 0<=port<=65535. If zero, the system will select an available port number. To find out which port number was selected, use getLocalPort(). |
References port.
|
inline |
Destructor.
Does not close the socket. You must explicitly close it with the close method.
|
inline |
Accept connection, return a connected Socket instance.
This method does the following in addition to the basic accept() system call.
Referenced by nidas::core::ServerSocket::connect(), main(), nidas::core::ServerSocketIODevice::open(), PSI::run(), ServerThread::run(), and nidas::util::McSocketMulticaster< SocketTT >::run().
void ServerSocket::close | ( | ) | ||
throw | ( | IOException | ||
) |
close the socket.
References _impl, nidas::util::SocketImpl::close(), DLOG, getDomain(), getLocalSocketAddress(), and nidas::util::SocketAddress::toString().
Referenced by nidas::core::ServerSocket::close(), nidas::core::ServerSocketIODevice::closeServerSocket(), PSI::run(), ServerThread::run(), nidas::util::McSocketMulticaster< SocketTT >::run(), and nidas::util::McSocketMulticaster< SocketTT >::~McSocketMulticaster().
|
inline |
Referenced by close().
|
inline |
|
inline |
Referenced by nidas::util::McSocketMulticaster< SocketTT >::run().
|
inline |
Fetch the local address that this socket is bound to.
Referenced by close(), nidas::core::RemoteSerialListener::getName(), and nidas::util::McSocketMulticaster< SocketTT >::run().
|
inline |
|
inline |
|
inline |
|
inline |
Referenced by nidas::core::ServerSocketIODevice::open().
|
inline |
|
inline |
nidas::util::ServerSocket::throw | ( | IOException | ) |
Create a ServerSocket bound to port on a given local address, and set listen backlog parameter.
nidas::util::ServerSocket::throw | ( | IOException | ) |
Create a ServerSocket bound to an address, and set listen backlog parameter.
|
protected |
Referenced by close().