source: trunk/MagicSoft/Cosy/tcpip/MTcpIpIO.h@ 9437

Last change on this file since 9437 was 9432, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 1.7 KB
Line 
1#ifndef COSY_MTcpIpIO
2#define COSY_MTcpIpIO
3
4#ifndef MARS_MThread
5#include "MThread.h"
6#endif
7#ifndef MARS_MTime
8#include "MTime.h"
9#endif
10
11
12class TString;
13class TSocket;
14class TServerSocket;
15
16// A generalized class for receiving over tcp/ip
17class MTcpIpI : public MThread
18{
19private:
20 Int_t fPortRx; // Port on which to listen for connections
21 Int_t fTimeout; // [ms] Timeout to listen for data to be received
22
23 Bool_t fConnectionEstablished;
24
25 Bool_t WaitForData(TSocket &sock);
26 void WaitForConnection(TServerSocket &server);
27
28 Int_t Thread();
29
30 virtual Bool_t ReadSocket(TSocket &rx) = 0;
31
32public:
33 MTcpIpI(Int_t rx, UInt_t timeout=5000) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fTimeout(timeout), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
34 ~MTcpIpI() { CancelThread(); }
35
36 Bool_t IsConnectionEstablished() const { return fConnectionEstablished; }
37};
38
39
40// A generalized class for sending over tcp/ip
41class MTcpIpO
42{
43private:
44 TSocket *fTxSocket;
45
46 Int_t fPortTx;
47
48public:
49 MTcpIpO(const char *addr, Int_t tx);
50 ~MTcpIpO();
51
52 static TString GetSocketAddress(const TSocket &s);
53 static bool SendFrame(TSocket &tx, const char *msg, int len);
54 static bool SendFrame(const char *addr, int port, const char *msg, int len);
55
56 TString GetSocketAddress() const;
57 bool Send(const char *msg, int len);
58};
59
60// This class es espcially meant to receive and send ascii messages
61class MTcpIpIO : public MTcpIpI, public MTcpIpO
62{
63private:
64 Bool_t ReadSocket(TSocket &rx);
65
66public:
67 MTcpIpIO(const char *addr, Int_t tx, Int_t rx);
68 ~MTcpIpIO();
69
70 virtual bool InterpreteStr(TString str);
71};
72
73#endif
Note: See TracBrowser for help on using the repository browser.