JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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 (jon@jsbsim.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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26HISTORY
27--------------------------------------------------------------------------------
2811/08/99 JSB Created
2911/08/07 HDW Added Generic Socket Send
30
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32SENTRY
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
34
35#ifndef FGfdmSocket_H
36#define FGfdmSocket_H
37
38/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39INCLUDES
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42#include "FGJSBBase.h"
43
44#if defined(_MSC_VER) || defined(__MINGW32__)
45 #include <winsock.h>
46 #include <io.h>
47 #undef ERROR
48#else
49 #include <netdb.h>
50#endif
51
52/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53FORWARD DECLARATIONS
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
56namespace JSBSim {
57
58/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59CLASS DOCUMENTATION
60%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
61
71/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72CLASS DECLARATION
73%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75class FGfdmSocket : public FGJSBBase
76{
77public:
86 FGfdmSocket(const std::string& address, int port, int protocol, int precision = 7);
87
95 FGfdmSocket(int port, int protocol, int precision = 7);
96
98
100 void Send(void);
101
108 void Send(const char *data, int length);
109 void Send(const std::string& data) { Send(data.c_str(), data.length()); }
110
116 std::string Receive(void);
117
124 int Reply(const std::string& text);
125
131 void Append(const std::string& s) {Append(s.c_str());}
132
138 void Append(const char*);
139
145 void Append(double value);
146
152 void Append(long value);
153
155 void Clear(void);
156
162 void Clear(const std::string& s);
163
165 void Close(void);
166
172 bool GetConnectStatus(void) {return connected;}
173
175 void WaitUntilReadable(void);
176
177 enum ProtocolType {ptUDP, ptTCP};
178
179private:
180#if defined(_MSC_VER) || defined(__MINGW32__)
181 SOCKET sckt;
182 SOCKET sckt_in;
183#else
184 int sckt;
185 int sckt_in;
186#endif
187 ProtocolType Protocol;
188 struct sockaddr_in scktName;
189 struct hostent *host;
190 std::ostringstream buffer;
191 int precision;
192 bool connected;
193 void LogSocketError(const std::string& msg);
194 void Debug(int from);
195};
196}
197#endif
JSBSim Base class.
Definition FGJSBBase.h:118
The FGfdmSocket class enables JSBSim to communicate via sockets.
Definition FGfdmSocket.h:76
std::string Receive(void)
Receive data from the socket connection.
bool GetConnectStatus(void)
Return the connection status of the socket.
void Clear(void)
Clear the internal buffer.
void Append(const std::string &s)
Append the specified string to the internal buffer.
void Close(void)
Close the socket connection if the protocol is TCP.
void WaitUntilReadable(void)
Wait until the TCP socket is readable.
int Reply(const std::string &text)
Send a reply to the client ending by a prompt "JSBSim>".
void Send(void)
Send the internal buffer over the socket connection.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71