Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a presumable first network interface setup.
Cannot find how to include the wincosk2.dll stuff though.
- Loading branch information
maartenl
committed
Apr 23, 2006
1 parent
5fa9b9a
commit 1a0130e
Showing
6 changed files
with
223 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters