Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CScommServer.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __BIASCScommServer__
26 #define __BIASCScommServer__
27 
28 #include "CScommBase.hh"
29 
30 //#include <Base/Common/BIASpragmaStart.hh>
31 
32 namespace BIAS {
33  /**
34  @class CScommServer
35  @brief class for sending/receiving data between clients and servers
36  @ingroup network
37  Only registered msgs will be accepted at the server side,
38  similar the client will accept only registered msgs from the server too.
39  The server waits on a DEFUALT_PORT for connections from clients,
40  which need to know the hostname of the server.
41  Usage: <br>
42 
43  -# Konstruktor: CScommServer Server;
44 
45  -# Register msgs: Server.RegisterMsg(msgName, BIAS::CS_FLOAT, 3);
46 
47  -# Enable receiver: Server.WaitForConnections();
48 
49  -# send and/or get Data: Server.SendMsg(msgName,vecOfFloats);<br>
50  Server.GetData(msgName, newVecOffloats);
51 
52  See the examples also.
53  @author Daniel Grest, Jan. 2004
54  */
55  class BIASNetworkComm_EXPORT CScommServer : public CScommBase {
56  public:
57 
58  /** Set threaded to false for deactivating the receive-thread. Data will be
59  read from TCP-buffer only when GetData methods are called. Threaded
60  receive is activated by default!
61  Beware: if there's no msg in tcp-buffer, GetData will BLOCK until there
62  is any new msg (this need not be the one GetData was called for,
63  for example binary instead of int)
64  if receive-buffer is completly filled, send blocks until msg
65  can be delivered!
66  */
67  CScommServer(bool threaded = true);
68  ~CScommServer();
69 
70  /** Init function, returns instantly and enables the server to accept
71  connections on the given port
72  */
73  void WaitForConnections(unsigned int port=D_CS_DEFAULT_PORT);
74 
75  protected:
76  void CreateListenThread_();
77  bool terminateListener_, listenThreadActive_;
78  pthread_t pthreadListener_;
79 
80  friend void* listenthread(void *data);
81  };
82 
83  /// these are wrapper to comply to the pthread_create() interface
84  void *listenthread(void *data);
85 
86 }
87 
88 //#include <Base/Common/BIASpragmaEnd.hh>
89 
90 #endif
void * listenthread(void *data)
these are wrapper to comply to the pthread_create() interface
class for sending/receiving data between clients and serversOnly registered msgs will be accepted at ...
Definition: CScommServer.hh:55
this class CScomm (ClientServer communciation) handles data comunication via TCP/IP for one server an...
Definition: CScommBase.hh:73
pthread_t pthreadListener_
Definition: CScommServer.hh:78