Skip to content

Commit

Permalink
added a presumable first network interface setup.
Browse files Browse the repository at this point in the history
Cannot find how to include the wincosk2.dll stuff though.
  • Loading branch information
maartenl committed Apr 23, 2006
1 parent 5fa9b9a commit 1a0130e
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 2 deletions.
125 changes: 125 additions & 0 deletions client/Network.cpp
@@ -0,0 +1,125 @@
/*-------------------------------------------------------------------------
svninfo: $Id: Database.java 1091 2006-03-08 22:05:19Z maartenl $
Maarten's Mud, WWW-based MUD using MYSQL
Copyright (C) 1998 Maarten van Leunen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Maarten van Leunen
Appelhof 27
5345 KA Oss
Nederland
Europe
maarten_l@yahoo.com
-------------------------------------------------------------------------*/
#include "Network.h"
#include <winsock2.h>

namespace Mmud {
//-------------------------------------------------------------------------------------
Network::Network(void)
{
LogManager *logger = Ogre::LogManager::getSingletonPtr();
// Initialize Winsock.
WSADATA wsaData;
int iResult = NO_ERROR;//WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
{
logger->logMessage("Error at WSAStartup()\n");
}
}

Network::~Network(void)
{
//WSACleanup();
}

void Network::open(void)//const String& anIp, const int aPort)
{
/*LogManager *logger = Ogre::LogManager::getSingletonPtr();
// Create a socket.
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( m_socket == INVALID_SOCKET ) {
logger->logMessage("Error at socket(): ");
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return;
}
// Connect to a server.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "10.0.10" );
clientService.sin_port = htons( 3340 );
if ( connect( m_socket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR)
{
logger->logMessage("Failed to connect.\n");
WSACleanup();
return;
}*/
}

void Network::close(void)//const String& anIp, const int aPort)
{
LogManager *logger = Ogre::LogManager::getSingletonPtr();
// Closing a socket.
if (m_socket != NULL)
{
//closesocket(m_socket);
m_socket = NULL;
}
logger->logMessage("Socket closed.\n");
}

void Network::send(void)//const String& aMessage)
{
// Send and receive data.
int bytesSent;

char sendbuf[32] = "Client: Sending data.";


/*bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );*/
LogManager *logger = Ogre::LogManager::getSingletonPtr();
logger->logMessage("Bytes Sent: ");
}

void Network::receive()
{
LogManager *logger = Ogre::LogManager::getSingletonPtr();
int bytesRecv = SOCKET_ERROR;
char recvbuf[32] = "";
if ( bytesRecv == 0 ||
(bytesRecv == SOCKET_ERROR ))//&&
// WSAGetLastError()== WSAECONNRESET ))
{
// bytesRecv = recv( m_socket, recvbuf, 32, 0 );
if ( bytesRecv == -1 )
{
logger->logMessage("Connection Closed.\n");
m_socket = NULL;
return;
}
if (bytesRecv < 0)
return;
logger->logMessage("Bytes Recv: ");
printf( "Bytes Recv: %ld\n", bytesRecv );
}
}
} // end of namespace
55 changes: 55 additions & 0 deletions client/Network.h
@@ -0,0 +1,55 @@
/*-------------------------------------------------------------------------
svninfo: $Id: Database.java 1091 2006-03-08 22:05:19Z maartenl $
Maarten's Mud, WWW-based MUD using MYSQL
Copyright (C) 1998 Maarten van Leunen
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Maarten van Leunen
Appelhof 27
5345 KA Oss
Nederland
Europe
maarten_l@yahoo.com
-------------------------------------------------------------------------*/
#ifndef __Network_h__
#define __Network_h__

#include <stdio.h>
#include <string.h>
#include <ogre.h>
#include <winsock2.h>

using namespace Ogre;
namespace Mmud
{

class Network
{
public:
Network(void);
virtual ~Network(void);

virtual void open(void);//const String&, const int);
virtual void send(void);//const String& aMessage);
virtual void receive(void);
virtual void close(void);

protected:
SOCKET m_socket;
};

} // end of namespace
#endif // __Network_h__
24 changes: 24 additions & 0 deletions client/OGRE sample.cbp
Expand Up @@ -62,6 +62,30 @@
<Add library="..\OgreSDK\lib\OgreMain.lib"/>
<Add directory="$(OGRE_HOME)\lib"/>
</Linker>
<Unit filename="Network.cpp">
<Option compilerVar="CPP"/>
<Option target="Debug"/>
<Option target="Release"/>
</Unit>
<Unit filename="Network.h">
<Option compilerVar=""/>
<Option compile="0"/>
<Option link="0"/>
<Option target="Debug"/>
<Option target="Release"/>
</Unit>
<Unit filename="OgreApplication.cpp">
<Option compilerVar="CPP"/>
<Option target="Debug"/>
<Option target="Release"/>
</Unit>
<Unit filename="OgreApplication.h">
<Option compilerVar=""/>
<Option compile="0"/>
<Option link="0"/>
<Option target="Debug"/>
<Option target="Release"/>
</Unit>
<Unit filename="main.cpp">
<Option compilerVar="CPP"/>
<Option target="Debug"/>
Expand Down
16 changes: 14 additions & 2 deletions client/OGRE sample.layout
@@ -1,7 +1,19 @@
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_layout_file>
<CodeBlocks_layout_file>
<File name="main.cpp" open="1" top="1">
<Cursor position="0" topLine="0"/>
<File name="Network.cpp" open="1" top="1">
<Cursor position="1592" topLine="12"/>
</File>
<File name="Network.h" open="1" top="0">
<Cursor position="1214" topLine="0"/>
</File>
<File name="OgreApplication.cpp" open="1" top="0">
<Cursor position="10057" topLine="0"/>
</File>
<File name="OgreApplication.h" open="1" top="0">
<Cursor position="1235" topLine="11"/>
</File>
<File name="main.cpp" open="1" top="0">
<Cursor position="1853" topLine="14"/>
</File>
</CodeBlocks_layout_file>
3 changes: 3 additions & 0 deletions client/OgreApplication.cpp
Expand Up @@ -26,6 +26,8 @@ maarten_l@yahoo.com
-------------------------------------------------------------------------*/
#include "OgreApplication.h"

namespace Mmud
{
//-------------------------------------------------------------------------------------
OgreApplication::OgreApplication(void)
: mRoot(0)
Expand Down Expand Up @@ -301,3 +303,4 @@ void OgreApplication::createFrameListener(void)
}


} // end of namespace
2 changes: 2 additions & 0 deletions client/OgreApplication.h
Expand Up @@ -32,6 +32,7 @@ maarten_l@yahoo.com
#include <ExampleFrameListener.h>

using namespace Ogre;
namespace Mmud {

class OgreApplication
{
Expand Down Expand Up @@ -66,4 +67,5 @@ class OgreApplication
ExampleFrameListener* mFrameListener;
};

} // end of namespace
#endif // __OgreApplication_h__

0 comments on commit 1a0130e

Please sign in to comment.