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

Last change on this file since 8864 was 8864, checked in by tbretz, 17 years ago
*** empty log message ***
File size: 1.5 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;
21 Bool_t fConnectionEstablished;
22
23 Bool_t WaitForData(TSocket &sock);
24 void WaitForConnection(TServerSocket &server);
25
26 Int_t Thread();
27
28 virtual Bool_t ReadSocket(TSocket &rx) = 0;
29
30public:
31 MTcpIpI(Int_t rx) : MThread(Form("MTcpIpI::%d", rx)), fPortRx(rx), fConnectionEstablished(kFALSE) { /*RunThread();*/ }
32 ~MTcpIpI() { CancelThread(); }
33
34 Bool_t IsConnectionEstablished() const { return fConnectionEstablished; }
35};
36
37
38// A generalized class for sending over tcp/ip
39class MTcpIpO
40{
41private:
42 TSocket *fTxSocket;
43
44public:
45 MTcpIpO(const char *addr, Int_t tx);
46 ~MTcpIpO();
47
48 static TString GetSocketAddress(const TSocket &s);
49 static bool SendFrame(TSocket &tx, const char *msg, int len);
50 static bool SendFrame(const char *addr, int port, const char *msg, int len);
51
52 TString GetSocketAddress() const;
53 bool Send(const char *msg, int len);
54};
55
56// This class es espcially meant to receive and send ascii messages
57class MTcpIpIO : public MTcpIpI, public MTcpIpO
58{
59private:
60 Bool_t ReadSocket(TSocket &rx);
61
62public:
63 MTcpIpIO(const char *addr, Int_t tx, Int_t rx);
64 ~MTcpIpIO();
65
66 virtual bool InterpreteStr(TString str);
67};
68
69#endif
Note: See TracBrowser for help on using the repository browser.