root/vtcross/branches/trnewman/src/socket/ServerSocket.cpp @ 35

Revision 35, 1.0 KB (checked in by trnewman, 16 years ago)

adding c++

Line 
1// Implementation of the ServerSocket class
2
3#include "ServerSocket.h"
4#include "SocketException.h"
5
6
7ServerSocket::ServerSocket ( int port )
8{
9  if ( ! Socket::create() )
10    {
11      throw SocketException ( "Could not create server socket." );
12    }
13
14  if ( ! Socket::bind ( port ) )
15    {
16      throw SocketException ( "Could not bind to port." );
17    }
18
19  if ( ! Socket::listen() )
20    {
21      throw SocketException ( "Could not listen to socket." );
22    }
23}
24
25ServerSocket::~ServerSocket()
26{
27}
28
29
30const ServerSocket& ServerSocket::operator << ( const std::string& s ) const
31{
32  if ( ! Socket::send ( s ) )
33    {
34      throw SocketException ( "Could not write to socket." );
35    }
36
37  return *this;
38
39}
40
41
42const ServerSocket& ServerSocket::operator >> ( std::string& s ) const
43{
44  if ( ! Socket::recv ( s ) )
45    {
46      throw SocketException ( "Could not read from socket." );
47    }
48
49  return *this;
50}
51
52void ServerSocket::accept ( ServerSocket& sock )
53{
54  if ( ! Socket::accept ( sock ) )
55    {
56      throw SocketException ( "Could not accept socket." );
57    }
58}
Note: See TracBrowser for help on using the browser.