#include <simgear/debug/logstream.hxx>
#include <simgear/io/lowlevel.hxx> // endian tests
+#include <simgear/io/sg_netBuffer.hxx>
#include <Main/fg_props.hxx>
#include <Network/native_ctrls.hxx>
#include "ExternalNet.hxx"
+class HTTPClient : public simgear::NetBufferChannel
+{
+
+ bool done;
+ SGTimeStamp start;
+
+public:
+
+ HTTPClient ( const char* host, int port, const char* path ) :
+ done( false )
+ {
+ open ();
+ connect (host, port);
+
+ char buffer[256];
+ ::snprintf (buffer, 256, "GET %s HTTP/1.0\r\n\r\n", path );
+ bufferSend(buffer, strlen(buffer) ) ;
+
+ start.stamp();
+ }
+
+ virtual void handleBufferRead (simgear::NetBuffer& buffer)
+ {
+ const char* s = buffer.getData();
+ while (*s)
+ fputc(*s++,stdout);
+
+ printf("done\n");
+ buffer.remove();
+ printf("after buffer.remove()\n");
+ done = true;
+ }
+
+ bool isDone() const { return done; }
+ bool isDone( long usec ) const {
+ if ( start + SGTimeStamp::fromUSec(usec) < SGTimeStamp::now() ) {
+ return true;
+ } else {
+ return done;
+ }
+ }
+};
+
FGExternalNet::FGExternalNet( double dt, string host, int dop, int dip, int cp )
{
// set_delta_t( dt );
#ifndef _EXTERNAL_NET_HXX
#define _EXTERNAL_NET_HXX
-#include <plib/netBuffer.h>
-#include <plib/netSocket.h>
-
#include <simgear/timing/timestamp.hxx> // fine grained timing measurements
+#include <simgear/io/raw_socket.hxx>
#include <Network/net_ctrls.hxx>
#include <Network/net_fdm.hxx>
#include <FDM/flight.hxx>
-class HTTPClient : public netBufferChannel
-{
-
- bool done;
- SGTimeStamp start;
-
-public:
-
- HTTPClient ( const char* host, int port, const char* path ) :
- done( false )
- {
- open ();
- connect (host, port);
-
- const char* s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path );
- bufferSend( s, strlen(s) ) ;
-
- start.stamp();
- }
-
- virtual void handleBufferRead (netBuffer& buffer)
- {
- const char* s = buffer.getData();
- while (*s)
- fputc(*s++,stdout);
-
- printf("done\n");
- buffer.remove();
- printf("after buffer.remove()\n");
- done = true;
- }
-
- bool isDone() const { return done; }
- bool isDone( long usec ) const {
- if ( start + SGTimeStamp::fromUSec(usec) < SGTimeStamp::now() ) {
- return true;
- } else {
- return done;
- }
- }
-};
-
-
class FGExternalNet: public FGInterface {
private:
int cmd_port;
string fdm_host;
- netSocket data_client;
- netSocket data_server;
+ simgear::Socket data_client;
+ simgear::Socket data_server;
bool valid;
if HAVE_FRAMEWORK_PLIB
fgfs_PLIB_FW = $(plib_FRAMEWORK)
-metar_PLIB_FW = $(plib_FRAMEWORK)
else
-fgfs_PLIB_LIBS = -lplibpuaux -lplibpu -lplibfnt -lplibjs -lplibnet \
+fgfs_PLIB_LIBS = -lplibpuaux -lplibpu -lplibfnt -lplibjs \
-lplibsg -lplibul
-metar_PLIB_LIBS = -lplibnet -lplibul
endif
if HAVE_FRAMEWORK_OSG
metar_LDADD = \
-lsgenvironment -lsgio -lsgbucket -lsgmisc -lsgstructure -lsgdebug \
- $(metar_PLIB_LIBS) $(network_LIBS) \
+ $(network_LIBS) \
-lz $(base_LIBS)
-metar_LDFLAGS = $(metar_PLIB_FW)
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
#include <simgear/props/props.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/math/sg_random.h>
+#include <simgear/io/raw_socket.hxx>
#include <Time/light.hxx>
#include <Aircraft/replay.hxx>
fgRegisterIdleHandler( &fgIdleFunction );
fgRegisterDrawHandler( &FGRenderer::update );
- // Initialize plib net interface
- netInit( &argc, argv );
+ // Initialize sockets (WinSock needs this)
+ simgear::Socket::initSockets();
// Clouds3D requires an alpha channel
fgOSOpenWindow(true /* request stencil buffer */);
#include <algorithm>
#include <cstring>
#include <osg/Math> // isNaN
-#include <plib/netSocket.h>
#include <simgear/misc/stdint.hxx>
#include <simgear/timing/timestamp.hxx>
SG_LOG(SG_NETWORK,SG_INFO,"FGMultiplayMgr::init-callsign= "<<mCallsign);
Close(); // Should Init be called twice, close Socket first
// A memory leak was reported here by valgrind
- mSocket = new netSocket();
+ mSocket = new simgear::Socket();
if (!mSocket->open(false)) {
SG_LOG( SG_NETWORK, SG_DEBUG,
"FGMultiplayMgr::init - Failed to create data socket" );
// returned will only be that of the next
// packet waiting to be processed.
//////////////////////////////////////////////////
- netAddress SenderAddress;
+ simgear::IPAddress SenderAddress;
bytes = mSocket->recvfrom(msgBuf.Msg, sizeof(msgBuf.Msg), 0,
&SenderAddress);
//////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
void
FGMultiplayMgr::ProcessPosMsg(const FGMultiplayMgr::MsgBuf& Msg,
- const netAddress& SenderAddress, long stamp)
+ const simgear::IPAddress& SenderAddress, long stamp)
{
const T_MsgHdr* MsgHdr = Msg.msgHdr();
if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + sizeof(T_PositionMsg)) {
//////////////////////////////////////////////////////////////////////
void
FGMultiplayMgr::ProcessChatMsg(const MsgBuf& Msg,
- const netAddress& SenderAddress)
+ const simgear::IPAddress& SenderAddress)
{
const T_MsgHdr* MsgHdr = Msg.msgHdr();
if (MsgHdr->MsgLen < sizeof(T_MsgHdr) + 1) {
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
-#include <plib/netSocket.h>
#include <Main/globals.hxx>
+#include <simgear/io/raw_socket.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <AIModel/AIMultiplayer.hxx>
const std::string& modelName);
FGAIMultiplayer* getMultiplayer(const std::string& callsign);
void FillMsgHdr(T_MsgHdr *MsgHdr, int iMsgId, unsigned _len = 0u);
- void ProcessPosMsg(const MsgBuf& Msg, const netAddress& SenderAddress,
+ void ProcessPosMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress,
long stamp);
- void ProcessChatMsg(const MsgBuf& Msg, const netAddress& SenderAddress);
+ void ProcessChatMsg(const MsgBuf& Msg, const simgear::IPAddress& SenderAddress);
/// maps from the callsign string to the FGAIMultiplayer
typedef std::map<std::string, SGSharedPtr<FGAIMultiplayer> > MultiPlayerMap;
MultiPlayerMap mMultiPlayerMap;
- netSocket* mSocket;
- netAddress mServer;
+ simgear::Socket* mSocket;
+ simgear::IPAddress mServer;
bool mHaveServer;
bool mInitialised;
std::string mCallsign;
#include <string>
-#include <plib/ul.h>
-#include <plib/netSocket.h>
-
#include "tiny_xdr.hxx"
/* XDR 8bit integers */
# include <config.h>
#endif
-#include <plib/netChat.h>
-
#include <simgear/misc/sg_path.hxx>
#include <Main/fg_props.hxx>
bool FGHttpd::process() {
- netChannel::poll();
+ simgear::NetChannel::poll();
return true;
}
# include <config.h>
#endif
-#include <plib/netChat.h>
+#include <simgear/io/sg_netChat.hxx>
#include "protocol.hxx"
/* simple httpd server that makes an hasty stab at following the http
1.1 rfc. */
-class HttpdChannel : public netChat
+class HttpdChannel : public simgear::NetChat
{
- netBuffer buffer ;
+ simgear::NetBuffer buffer ;
string urlEncode(string);
string urlDecode(string);
} ;
-class HttpdServer : private netChannel
+class HttpdServer : private simgear::NetChannel
{
virtual bool writable (void) { return false ; }
virtual void handleAccept (void) {
- netAddress addr ;
+ simgear::IPAddress addr ;
int handle = accept ( &addr ) ;
SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );
bool FGJpegHttpd::process() {
- netChannel::poll();
+ simgear::NetChannel::poll();
return true;
}
# include <config.h>
#endif
-#include <plib/netChat.h>
+#include <simgear/io/sg_netChat.hxx>
#ifdef FG_JPEG_SERVER
# include <simgear/screen/jpgfactory.hxx>
/* simple httpd server that makes an hasty stab at following the http
1.1 rfc. */
-class HttpdImageChannel : public netChat
+class HttpdImageChannel : public simgear::NetChat
{
- netBuffer buffer ;
+ simgear::NetBuffer buffer ;
trJpgFactory *JpgFactory;
public:
};
-class HttpdImageServer : private netChannel
+class HttpdImageServer : private simgear::NetChannel
{
virtual bool writable (void) { return false ; }
virtual void handleAccept (void) {
- netAddress addr ;
+ simgear::IPAddress addr ;
int handle = accept ( &addr ) ;
SG_LOG( SG_IO, SG_INFO, "Client " << addr.getHost() << ":" << addr.getPort() << " connected" );
#include <Main/globals.hxx>
#include <Main/viewmgr.hxx>
-#include <plib/netChat.h>
+#include <simgear/io/sg_netChat.hxx>
#include "props.hxx"
* Props connection class.
* This class represents a connection to props client.
*/
-class PropsChannel : public netChat
+class PropsChannel : public simgear::NetChat
{
- netBuffer buffer;
+ simgear::NetBuffer buffer;
/**
* Current property node name.
return false;
}
- netChannel::open();
- netChannel::bind( "", port );
- netChannel::listen( 5 );
+ simgear::NetChannel::open();
+ simgear::NetChannel::bind( "", port );
+ simgear::NetChannel::listen( 5 );
SG_LOG( SG_IO, SG_INFO, "Props server started on port " << port );
set_enabled( true );
bool
FGProps::process()
{
- netChannel::poll();
+ simgear::NetChannel::poll();
return true;
}
void
FGProps::handleAccept()
{
- netAddress addr;
+ simgear::IPAddress addr;
int handle = accept( &addr );
SG_LOG( SG_IO, SG_INFO, "Props server accepted connection from "
<< addr.getHost() << ":" << addr.getPort() );
#include <string>
#include <vector>
-using std::string;
-using std::vector;
-
-#include <plib/netChannel.h>
+#include <simgear/io/sg_netChannel.hxx>
#include "protocol.hxx"
* FlightGear properties.
*/
class FGProps : public FGProtocol,
- public netChannel
+ public simgear::NetChannel
{
private:
*
* @param tokens Tokenized configuration parameters
*/
- FGProps( const vector<string>& tokens );
+ FGProps( const std::vector<std::string>& tokens );
/**
* Destructor.
AM_CPPFLAGS = $(svn_CPPFLAGS)
-if HAVE_FRAMEWORK_PLIB
-terrasync_LDFLAGS = $(plib_FRAMEWORK)
-else
-terrasync_PLIB_LIBS = -lplibnet -lplibul
-endif
-
-terrasync_LDADD = $(terrasync_PLIB_LIBS) -lsgmisc -lsgdebug $(network_LIBS) $(svn_LIBS)
+terrasync_LDADD = -lsgio -lsgmisc -lsgdebug $(network_LIBS) $(svn_LIBS)
#include <deque>
#include <map>
-#include <plib/netSocket.h>
-#include <plib/ul.h>
-
+#include <simgear/io/raw_socket.hxx>
#include <simgear/bucket/newbucket.hxx>
#include <simgear/misc/sg_path.hxx>
deque<string> waitingTiles;
typedef map<string,time_t> CompletedTiles;
CompletedTiles completedTiles;
-netSocket theSocket;
+simgear::Socket theSocket;
#ifdef HAVE_SVN_CLIENT_H
}
// Must call this before any other net stuff
- netInit( &argc,argv );
+ simgear::Socket::initSockets();
if ( ! theSocket.open( false ) ) { // open a UDP socket
printf("error opening socket\n");
terminating = true;
} else
- ulSleep( 1 );
+ #ifdef _WIN32
+ Sleep(1000);
+#else
+ sleep(1);
+#endif
} // while !terminating
return 0;