- Timestamp:
- Apr 27, 2006, 5:06:47 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/netdefs.h
r6695 r7402 28 28 } NodeType; 29 29 30 typedef enum ConnectionType { 31 NET_UDP = 0, 32 NET_TCP 33 }; 34 30 35 31 36 typedef enum { -
branches/network/src/lib/network/server_socket.cc
r6139 r7402 26 26 #include "debug.h" 27 27 28 ServerSocket::ServerSocket( ) 28 29 ServerSocket::ServerSocket( ConnectionType connectionType ) 29 30 { 31 this->connectionType = connectionType; 30 32 init(); 31 33 } 32 34 33 ServerSocket::ServerSocket( unsigned int port ) 35 36 ServerSocket::ServerSocket( ConnectionType connectionType, unsigned int port ) 34 37 { 38 this->connectionType = connectionType; 35 39 init(); 36 40 listen(port); 37 41 } 42 43 44 ServerSocket::ServerSocket() 45 { 46 this->connectionType == NET_TCP; 47 init(); 48 } 49 50 51 ServerSocket::ServerSocket( unsigned int port ) 52 { 53 this->connectionType == NET_TCP; 54 init(); 55 listen(port); 56 } 57 38 58 39 59 /** … … 49 69 _isListening = false; 50 70 } 71 72 73 51 74 52 75 void ServerSocket::init( ) … … 97 120 } 98 121 99 listenSocket = SDLNet_TCP_Open(&ip); 100 101 if (!listenSocket) 122 if( this->connectionType == NET_TCP) 102 123 { 103 PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError()); 124 listenSocketTCP = SDLNet_TCP_Open(&ip); 125 if( !listenSocketTCP) { 126 PRINTF(1)("SDLNet_TCP_Open: %s\n", SDLNet_GetError()); 127 _isListening = false; 128 return false; 129 } 130 } 131 else 132 { 133 listenSocketUDP = SDLNet_UDP_Open(port); 134 PRINTF(1)("SDLNet_UDP_Open: %s\n", SDLNet_GetError()); 104 135 _isListening = false; 105 136 return false; 106 137 } 138 107 139 108 140 return true; … … 110 142 111 143 144 /** 145 * returns a new NetworkSocket 146 * @return new socket 147 */ 112 148 NetworkSocket* ServerSocket::getNewSocket( ) 113 149 { … … 119 155 } 120 156 121 TCPsocket sock = SDLNet_TCP_Accept(listenSocket); 122 123 if ( !sock ) 157 if( this->connectionType == NET_TCP) 124 158 { 125 return NULL; 159 TCPsocket sockTCP = SDLNet_TCP_Accept(this->listenSocketTCP); 160 if( !sockTCP) 161 return NULL; 162 else 163 return new NetworkSocket(sockTCP); 126 164 } 127 165 else 128 166 { 129 return new NetworkSocket(sock); 167 #warning UDP getNewSocket incomplet 168 // UDPsocket sockUDP = SDLNet_UDP_Accept(this->listenSocketUDP); 169 // if( !sockUDP) 170 // return NULL; 171 172 // else 173 // return new NetworkSocket(); 130 174 } 131 175 } 132 176 177 178 /** 179 * closes the ServerSocket 180 */ 133 181 void ServerSocket::close( ) 134 182 { -
branches/network/src/lib/network/server_socket.h
r6981 r7402 24 24 #define _MSECONDS_SLEEP_LISTEN 100 25 25 26 26 27 class ServerSocket : public BaseObject 27 28 { 28 private: 29 TCPsocket listenSocket; 30 bool terminateThread; 29 public: 30 #warning old socket structure 31 ServerSocket(); 32 ServerSocket(unsigned int port); 31 33 32 bool _isListening; 34 ServerSocket(ConnectionType connectionType); 35 ServerSocket(ConnectionType connectionType, unsigned int port ); 36 virtual ~ServerSocket(); 33 37 34 void init();35 36 public:37 ServerSocket();38 ServerSocket( unsigned int port );39 virtual ~ServerSocket();40 38 bool listen( unsigned int port ); 41 39 NetworkSocket* getNewSocket( void ); 42 40 void close(); 43 41 inline bool isOk(){ return listenSocket!=NULL; } 42 43 44 private: 45 void init(); 46 47 48 private: 49 #warning old socket structure 50 TCPsocket listenSocket; 51 52 ConnectionType connectionType; //!< the connection type of the socket {TCP,UDP} 53 TCPsocket listenSocketTCP; //!< tcp socket 54 UDPsocket listenSocketUDP; //!< udp socket 55 bool terminateThread; //!< true if thread terminated 56 57 bool _isListening; //!< true if listening 58 59 44 60 }; 45 61
Note: See TracChangeset
for help on using the changeset viewer.