]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGfdmSocket.h
Update to the latest version of JSBSim which supports Lighter Than Air craft
[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 <stdio.h>
43
44 #ifdef FGFS
45 #  include <simgear/compiler.h>
46 #  include STL_STRING
47 #  include STL_IOSTREAM
48 #  include STL_FSTREAM
49    SG_USING_STD(cout);
50    SG_USING_STD(endl);
51 #else
52 #  include <string>
53 #  if defined(sgi) && !defined(__GNUC__) && (_COMPILER_VERSION < 740)
54 #    include <iostream.h>
55 #    include <fstream.h>
56 #  else
57 #    include <iostream>
58 #    include <fstream>
59      using std::cout;
60      using std::endl;
61 #  endif
62 #endif
63
64 #include <sys/types.h>
65 #include "FGJSBBase.h"
66
67 #if defined(__BORLANDC__) || defined(_MSC_VER) || defined(__MINGW32__)
68   #include <winsock.h>
69   #include <io.h>
70 #else
71   #include <unistd.h>
72   #include <sys/socket.h>
73   #include <netinet/in.h>
74   #include <netdb.h>
75   #include <errno.h>
76   #include <sys/ioctl.h>
77 #endif
78
79 #ifdef _MSC_VER
80
81 #pragma comment (lib,"WSock32.lib")
82
83 #endif
84
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 DEFINITIONS
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
88
89 #define ID_FDMSOCKET "$Id$"
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 FORWARD DECLARATIONS
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 namespace JSBSim {
96
97 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98 CLASS DOCUMENTATION
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
100
101 /** Encapsulates an object that enables JSBSim to communicate via socket (input
102     and/or output).
103     
104   */
105
106 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 CLASS DECLARATION
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
109
110 using std::string;
111 using std::cerr;
112
113 class FGfdmSocket : public FGJSBBase
114 {
115 public:
116   FGfdmSocket(string, int);
117   FGfdmSocket(string, int, int);
118   FGfdmSocket(int);
119   ~FGfdmSocket();
120   void Send(void);
121   void Send(char *data, int length);
122
123   string Receive(void);
124   int Reply(string text);
125   void Append(const string s) {Append(s.c_str());}
126   void Append(const char*);
127   void Append(double);
128   void Append(long);
129   void Clear(void);
130   void Clear(string s);
131   void Close(void);
132   bool GetConnectStatus(void) {return connected;}
133
134   enum {ptUDP, ptTCP};
135
136 private:
137   int sckt;
138   int sckt_in;
139   int size;
140   struct sockaddr_in scktName;
141   struct hostent *host;
142   string buffer;
143   bool connected;
144   void Debug(int from);
145 };
146 }
147 #endif