]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGfdmSocket.h
don't forget to include the new header for the tardist
[flightgear.git] / src / FDM / JSBSim / input_output / FGfdmSocket.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGfdmSocket.h
4  Author:       Jon S. Berndt
5  Date started: 11/08/99
6
7  ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 11/08/99   JSB   Created
29 11/08/07   HDW   Added Generic Socket Send
30
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 SENTRY
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35 #ifndef FGfdmSocket_H
36 #define FGfdmSocket_H
37
38 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42 #include <cstdio>
43 #include <string>
44 #include <iostream>
45 #include <fstream>
46 #include <sys/types.h>
47 #include "FGJSBBase.h"
48
49 using std::cout;
50 using std::endl;
51
52 #if defined(_MSC_VER) || defined(__MINGW32__)
53   #include <winsock.h>
54   #include <io.h>
55 #else
56   #include <unistd.h>
57   #include <sys/socket.h>
58   #include <netinet/in.h>
59   #include <netdb.h>
60   #include <errno.h>
61   #include <sys/ioctl.h>
62 #endif
63
64 #ifdef _MSC_VER
65 #  pragma comment (lib,"WSock32.lib")
66 #endif
67
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 DEFINITIONS
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
71
72 #define ID_FDMSOCKET "$Id$"
73
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75 FORWARD DECLARATIONS
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77
78 namespace JSBSim {
79
80 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 CLASS DOCUMENTATION
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
83
84 /** Encapsulates an object that enables JSBSim to communicate via socket (input
85     and/or output).
86     
87   */
88
89 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 CLASS DECLARATION
91 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
92
93 using std::string;
94 using std::cerr;
95
96 class FGfdmSocket : public FGJSBBase
97 {
98 public:
99   FGfdmSocket(string, int);
100   FGfdmSocket(string, int, int);
101   FGfdmSocket(int);
102   ~FGfdmSocket();
103   void Send(void);
104   void Send(char *data, int length);
105
106   string Receive(void);
107   int Reply(string text);
108   void Append(const string s) {Append(s.c_str());}
109   void Append(const char*);
110   void Append(double);
111   void Append(long);
112   void Clear(void);
113   void Clear(string s);
114   void Close(void);
115   bool GetConnectStatus(void) {return connected;}
116
117   enum {ptUDP, ptTCP};
118
119 private:
120   int sckt;
121   int sckt_in;
122   int size;
123   struct sockaddr_in scktName;
124   struct hostent *host;
125   string buffer;
126   bool connected;
127   void Debug(int from);
128 };
129 }
130 #endif