Main Page Namespace List Class Hierarchy Alphabetical List Compound List File List Namespace Members Compound Members File Members Related Pages
ssobjects::SocketInstance Class Reference
The socket that you use to connect with.
More...
#include <socketinstance.h>
Inheritance diagram for ssobjects::SocketInstance::
List of all members.
Public Methods |
| SocketInstance () |
SOCKET | getSocket () const |
void | setExceptionOnReadClose (const bool bThrowException=true) |
| Toggles exceptions on read closers. More...
|
void | cleanup () |
void | create (const int nType=SOCK_STREAM) |
void | close () |
void | bind (LPCSOCKADDR psa) |
void | listen () |
void | connect (LPCSOCKADDR psa) |
bool | accept (SocketInstance &s, LPSOCKADDR psa) |
bool | accept (SocketInstance *s, LPSOCKADDR psa) |
int | send (const char *pch, const int nSize, const int nSecs=DEFAULT_SOCKET_TIMEOUT) |
int | write (const char *pch, const int nSize, const int nSecs=DEFAULT_SOCKET_TIMEOUT) |
int | recv (char *pch, const int nSize, const int nSecs=DEFAULT_SOCKET_TIMEOUT) |
int | sendDatagram (const char *pch, const int nSize, LPCSOCKADDR psa, const int nSecs=10) |
int | receiveDatagram (char *pch, const int nSize, LPSOCKADDR psa, const int nSecs=10) |
void | getPeerAddr (LPSOCKADDR psa) |
void | getSockAddr (LPSOCKADDR psa) |
| operator SOCKET () |
SocketInstance& | operator= (const SocketInstance &s) |
| SocketInstance (const SocketInstance &s) |
Public Attributes |
SOCKET | m_hSocket |
bool | m_bThrowExceptionOnReadClose |
Static Public Methods |
SockAddr | getHostByName (const char *pchName, const USHORT ushPort=0) |
const char* | getHostByAddr (LPCSOCKADDR psa) |
Detailed Description
The socket that you use to connect with.
The SocketInstance object is the lowest level in the socket layer. It provides access methods to read and write to a socket un TCP/IP or UDP mode.
Typical client session would look like this:
...
SocketInstance sConnection;
try
{
//open connection
puts("Connecting to server...");
SockAddr saServer(szHost,iPort);
if(isalpha(szHost[0])) //check if szHost is in "host.com" format or "255.255.255.255"
saServer = SocketInstance::getHostByName(szHost,iPort);
sConnection.create();
sConnection.connect(saServer);
//we are connected, do something useful
...
sConnection.close();
}
catch(GeneralException* e)
{
sConnection.cleanup();
LOG("error s",e->getErrorMsg());
}
...
A server would look like this:
...
SocketInstance sClient;
SockAddr saClient;
SockAddr saServer(INADDR_ANY,atoi(argv[1]));
SocketInstance sListen;
try
{
sListen.create();
sListen.bind(saServer);
sListen.listen();
while(bWantMoreConnections)
{
sListen.accept(sClient,saClient);
//we got a connection ...
sClient.close();
}
sListen.close();
}
catch(GeneralException* e)
{
sConnection.cleanup();
LOG("error s",e->getErrorMsg());
}
...
Constructor & Destructor Documentation
ssobjects::SocketInstance::SocketInstance (
|
) [inline]
|
|
ssobjects::SocketInstance::SocketInstance (
|
const SocketInstance & s ) [inline]
|
|
Member Function Documentation
bool ssobjects::SocketInstance::accept (
|
SocketInstance * s,
|
|
LPSOCKADDR psa )
|
|
bool ssobjects::SocketInstance::accept (
|
SocketInstance & s,
|
|
LPSOCKADDR psa )
|
|
void ssobjects::SocketInstance::bind (
|
LPCSOCKADDR psa )
|
|
void ssobjects::SocketInstance::cleanup (
|
)
|
|
void ssobjects::SocketInstance::close (
|
)
|
|
void ssobjects::SocketInstance::connect (
|
LPCSOCKADDR psa )
|
|
void ssobjects::SocketInstance::create (
|
const int nType = SOCK_STREAM )
|
|
const char * ssobjects::SocketInstance::getHostByAddr (
|
LPCSOCKADDR psa ) [static]
|
|
SockAddr ssobjects::SocketInstance::getHostByName (
|
const char * pchName,
|
|
const USHORT ushPort = 0 ) [static]
|
|
void ssobjects::SocketInstance::getPeerAddr (
|
LPSOCKADDR psa )
|
|
void ssobjects::SocketInstance::getSockAddr (
|
LPSOCKADDR psa )
|
|
SOCKET ssobjects::SocketInstance::getSocket (
|
) const [inline]
|
|
void ssobjects::SocketInstance::listen (
|
)
|
|
ssobjects::SocketInstance::operator SOCKET (
|
) [inline]
|
|
SocketInstance & ssobjects::SocketInstance::operator= (
|
const SocketInstance & s )
|
|
int ssobjects::SocketInstance::receiveDatagram (
|
char * pch,
|
|
const int nSize,
|
|
LPSOCKADDR psa,
|
|
const int nSecs = 10 )
|
|
int ssobjects::SocketInstance::recv (
|
char * pch,
|
|
const int nSize,
|
|
const int nSecs = DEFAULT_SOCKET_TIMEOUT )
|
|
|
Read in data from connected socket. If m_bThrowExceptionOnReadClose is set, and the socket is closed gracefully on the other end, an exception is throw. If not set, SocketInstance::recv will return 0 bytes. -
Exceptions:
-
SocketInstanceException
|
If there was an error during the read operation, or the socket was closed. |
|
int ssobjects::SocketInstance::send (
|
const char * pch,
|
|
const int nSize,
|
|
const int nSecs = DEFAULT_SOCKET_TIMEOUT )
|
|
int ssobjects::SocketInstance::sendDatagram (
|
const char * pch,
|
|
const int nSize,
|
|
LPCSOCKADDR psa,
|
|
const int nSecs = 10 )
|
|
void ssobjects::SocketInstance::setExceptionOnReadClose (
|
const bool bThrowException = true )
|
|
|
Toggles exceptions on read closers.
When read exceptions are set, all socket errors, and closers will throw an exeption. Sometimes however it is desirable not to throw an exception when the connection was gracefully closed on the other end. In this case recv will return 0 bytes read. -
Parameters:
-
bThrowException
|
true causes exceptions will be thrown. false causes recv to return 0 bytes read. |
|
int ssobjects::SocketInstance::write (
|
const char * pch,
|
|
const int nSize,
|
|
const int nSecs = DEFAULT_SOCKET_TIMEOUT )
|
|
Member Data Documentation
bool ssobjects::SocketInstance::m_bThrowExceptionOnReadClose
|
|
SOCKET ssobjects::SocketInstance::m_hSocket
|
|
The documentation for this class was generated from the following files:
Generated at Tue Sep 25 00:26:37 2001 for SimpleServerObjects by
1.2.7 written by Dimitri van Heesch,
© 1997-2001