ServerThread Class Reference
#include <ServerThread.h>

Static Public Member Functions | |
| static bool | init (int serverport) |
| static void | run (void *serverport) |
| static void | kill () |
Static Protected Member Functions | |
| static bool | handShake (OSG::StreamSocket *socket, UserNetworkIdentification *otherID, OSG::UInt32 &tag) |
| static bool | handleNormalConnect (OSG::StreamSocket *socket, NetMessage &message) |
| static bool | handleQuickConnect (OSG::StreamSocket *socket, NetMessage &message, UserNetworkIdentification *otherID) |
Static Protected Attributes | |
| static volatile bool | shutdown = false |
| static int | port |
| static OSG::StreamSocket | client |
| static Network * | internalNetwork = NULL |
Friends | |
| class | Network |
Detailed Description
This class listens for incoming connections and manages the connection of new clients in an existing network.Member Function Documentation
| static bool ServerThread::handleNormalConnect | ( | OSG::StreamSocket * | socket, | |
| NetMessage & | message | |||
| ) | [static, protected] |
| static bool ServerThread::handleQuickConnect | ( | OSG::StreamSocket * | socket, | |
| NetMessage & | message, | |||
| UserNetworkIdentification * | otherID | |||
| ) | [static, protected] |
| static bool ServerThread::handShake | ( | OSG::StreamSocket * | socket, | |
| UserNetworkIdentification * | otherID, | |||
| OSG::UInt32 & | tag | |||
| ) | [static, protected] |
This method makes the handshake between client and server to check, if the client is allowed or is able to connect to the network. For this it first receives a message from the client in which the client's NetworkIdentification and the connection type (normal or quick) is stored. With the ID the method first checks if the client is already connected to the local machine. If so, the connection is refused. The method then distinguishes between a quickConnect or a normal connection request. If the connection type is a quickConnect, the method adds the client to the socketList and sends a message with a connectionRequestOkTag back to the client. If it is a normal connection the method checks, if every client in the net is ready for a new connection (or if another client is already connecting) by calling the checkConnection method from class Network. If everyone in the net is ready for a new connection, the method sends a message with the local NetworkIdentification and a list of IDs of all other members in the net. The method then waits for a response message from the client saying that the client is done and then sends a message to all other members in the network that the connection request is finished.
- Parameters:
-
otherID pointer to the NetworkIdentification-Object for creation of a new socketListEntry tag type of Message (quickConnectTag or normalMessageTag)
- Returns:
- true, if connection of client worked
| OSG_USING_NAMESPACE bool ServerThread::init | ( | int | serverport | ) | [static] |
This method initializes the ServerThread. It opens a TCP socket with the port passed as parameter and starts listening for connections.
- Parameters:
-
serverport port for incoming connections
- Returns:
- true, if initialization succeeded
| void ServerThread::kill | ( | ) | [static] |
This method tells the ServerThread to leave it's loop and enter the cleanupBarrier.
| void ServerThread::run | ( | void * | serverport | ) | [static] |
This is the main method of the ServerThread. It waits for incoming connections, calls the handShake method for each new connection and adds the new connections to the socketList if everything worked. It runs until the kill method is called, then it enters the cleanupBarrier and waits for the other Threads (SendRecvThread and Main-thread) to shutdown. When the first client tries to connect the local IP-Address is taken from the opened socket and stored in the NetworkIdentification myId in class Network.
- Parameters:
-
dummy just a dummy parameter for Thread construction
Friends And Related Function Documentation
friend class Network [friend] |
Member Data Documentation
StreamSocket ServerThread::client [static, protected] |
Network * ServerThread::internalNetwork = NULL [static, protected] |
int ServerThread::port [static, protected] |
volatile bool ServerThread::shutdown = false [static, protected] |
The documentation for this class was generated from the following files:
- src/inVRs/Modules/Network/ServerThread.h
- src/inVRs/Modules/Network/ServerThread.cpp
Generated on Wed Oct 20 16:12:00 2010 for inVRs by
1.5.8