FlightGear next
FGfdmSocket.h
Go to the documentation of this file.
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#else
48 #include <netdb.h>
49#endif
50
51/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52FORWARD DECLARATIONS
53%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55namespace JSBSim {
56
57/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58CLASS DOCUMENTATION
59%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60
65
66/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67CLASS DECLARATION
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70class FGfdmSocket : public FGJSBBase
71{
72public:
73 FGfdmSocket(const std::string& address, int port, int protocol, int precision = 7);
74 FGfdmSocket(int port, int protocol, int precision = 7);
76 void Send(void);
77 void Send(const char *data, int length);
78
79 std::string Receive(void);
80 int Reply(const std::string& text);
81 void Append(const std::string& s) {Append(s.c_str());}
82 void Append(const char*);
83 void Append(double);
84 void Append(long);
85 void Clear(void);
86 void Clear(const std::string& s);
87 void Close(void);
88 bool GetConnectStatus(void) {return connected;}
89 void WaitUntilReadable(void);
90
92
93private:
94#if defined(_MSC_VER) || defined(__MINGW32__)
95 SOCKET sckt;
96 SOCKET sckt_in;
97#else
98 int sckt;
99 int sckt_in;
100#endif
101 ProtocolType Protocol;
102 struct sockaddr_in scktName;
103 struct hostent *host;
104 std::ostringstream buffer;
105 int precision;
106 bool connected;
107 void Debug(int from);
108};
109}
110#endif
FGJSBBase()
Constructor for FGJSBBase.
Definition FGJSBBase.h:81
int Reply(const std::string &text)
void Append(const std::string &s)
Definition FGfdmSocket.h:81
bool GetConnectStatus(void)
Definition FGfdmSocket.h:88
void WaitUntilReadable(void)
FGfdmSocket(const std::string &address, int port, int protocol, int precision=7)
void Clear(const std::string &s)
std::string Receive(void)