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

Last change on this file since 9306 was 8865, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 1.6 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
46public:
47 MTcpIpO(const char *addr, Int_t tx);
48 ~MTcpIpO();
49
50 static TString GetSocketAddress(const TSocket &s);
51 static bool SendFrame(TSocket &tx, const char *msg, int len);
52 static bool SendFrame(const char *addr, int port, const char *msg, int len);
53
54 TString GetSocketAddress() const;
55 bool Send(const char *msg, int len);
56};
57
58// This class es espcially meant to receive and send ascii messages
59class MTcpIpIO : public MTcpIpI, public MTcpIpO
60{
61private:
62 Bool_t ReadSocket(TSocket &rx);
63
64public:
65 MTcpIpIO(const char *addr, Int_t tx, Int_t rx);
66 ~MTcpIpIO();
67
68 virtual bool InterpreteStr(TString str);
69};
70
71#endif
Note: See TracBrowser for help on using the repository browser.