Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Network Class Reference

The Network Class Class for network functions. More...

#include <network.h>

List of all members.

Public Methods

 Network ()
 The Constructor. More...

 ~Network ()
 The Deconstructor. More...

int waitForConnection ()
 Waits for Connections. More...


Private Attributes

int sock
 The own server socket. More...

struct sockaddr_in address
 The address. More...


Detailed Description

The Network Class Class for network functions.

Author(s):
StonedBones
Date:
310100

Definition at line 17 of file network.h.

00017 {
00018     public:
00020     Network ();
00022     ~Network ();
00023 
00025 
00028     int waitForConnection ();
00029 
00030     private:
00031     int                sock; 
00032     struct sockaddr_in address; 
00033 }

Constructor & Destructor Documentation

Network::Network ()

The Constructor.

Definition at line 34 of file network.cpp.

00034 {
00035     extern FrontEnd* frontEnd;
00036     
00037     string msg;
00038     
00039     frontEnd->displayDebugMessage ("Opening TCP/IP socket");
00040     
00041     if ((sock = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
00042     frontEnd->displayDebugMessage ("Error: Can't open TCP/IP socket !");
00043     exit (1);
00044     };
00045     
00046     int i = 1;
00047     setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &i, sizeof (i));
00048     
00049     address.sin_family = AF_INET;
00050     address.sin_port   = htons (DEFAULT_PORT);
00051     
00052     memset (&address.sin_addr, 0, sizeof (address.sin_addr));
00053     
00054     msg = "Binding TCP/IP socket to port ";
00055     msg += intToChar (DEFAULT_PORT);
00056     frontEnd->displayDebugMessage (msg.c_str ());
00057     
00058     if (bind (sock, (struct sockaddr*) &address, sizeof (address))) {
00059     frontEnd->displayDebugMessage ("Error: Can't bind TCP/IP socket !");
00060     exit (1);
00061     };
00062     
00063     frontEnd->displayDebugMessage ("Listening for connections");
00064     
00065     if (listen (sock, 5)) {
00066     frontEnd->displayDebugMessage ("Error: Can't listen to socket !");
00067     exit (1);
00068     };
00069 }

Network::~Network ()

The Deconstructor.

Definition at line 82 of file network.cpp.

00082 {
00083 }

Member Function Documentation

int Network::waitForConnection ()

Waits for Connections.

Returns:
the socket number of the new client

Definition at line 96 of file network.cpp.

00096 {
00097     extern FrontEnd* frontEnd;
00098     
00099     fd_set checkIt;
00100     int    clientSock = 0;
00101     
00102     FD_ZERO (&checkIt);
00103     FD_SET  (sock, &checkIt);
00104     
00105     if (select (70, &checkIt, 0, 0, NULL) < 0) {
00106     frontEnd->displayDebugMessage ("Error in Network::waitForConnection: select !");
00107     exit (1);
00108     };
00109     
00110     if (FD_ISSET (sock, &checkIt)) {
00111     if ((clientSock = accept (sock, (struct sockaddr*) &address, (socklen_t*) sizeof (address))) < 0) {
00112         frontEnd->displayDebugMessage ("Error in Network::waitForConnection: accept !");
00113         exit (1);
00114     };
00115     } else {
00116     frontEnd->displayDebugMessage ("Error in Network::waitForConnection: FD_ISSET !");
00117     exit (1);
00118     };
00119     
00120     return clientSock;
00121 }

Member Data Documentation

struct sockaddr_in Network::address [private]

The address.

Definition at line 32 of file network.h.

int Network::sock [private]

The own server socket.

Definition at line 31 of file network.h.


The documentation for this class was generated from the following files:
Generated at Sat May 13 13:50:25 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000