diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 8a2081c0..99cba856 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -26,8 +26,8 @@ bool Connection::Connect(unsigned short port , const char serverName[]) } - struct hostent *hostEntry; - if((hostEntry = gethostbyname(serverName)) == NULL) + struct hostent *hostEnt; + if((hostEnt = gethostbyname(serverName)) == NULL) { //couldn't find host return false; @@ -35,7 +35,7 @@ bool Connection::Connect(unsigned short port , const char serverName[]) struct sockaddr_in server; server.sin_family = AF_INET; server.sin_port = htons(port); - server.sin_addr.s_addr = *(unsigned long*) hostEntry->h_addr; + server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr; while(1) { @@ -77,7 +77,7 @@ bool Connection::InitiateServer(unsigned short port) return false; } - //not our Listen function! + //not our Listen function! its trying to keep our socket open for connections if(listen(mySocket, 5) == SOCKET_ERROR) { //"Listen failed! @@ -94,12 +94,13 @@ void Connection::Disconnect() closesocket(mySocket); } -bool Connection::Send(const char message[]) +bool Connection::Send(const unsigned char message[]) { int nBytes; - unsigned long messageSize = strlen(message); - - if((nBytes = send(mySocket, message , messageSize, 0)) == SOCKET_ERROR) + unsigned long messageSize = strlen((char*)message); + messageSize = 18; + nBytes = send(mySocket, (char*)message , messageSize, 0); + if(nBytes == SOCKET_ERROR) { //Send failed! return false; @@ -108,10 +109,10 @@ bool Connection::Send(const char message[]) return true; } -int Connection::Recieve(char message[]) +int Connection::Recieve(unsigned char message[]) { int nBytes; - nBytes = recv(mySocket, message , 255, 0); + nBytes = recv(mySocket, (char*)message , 255, 0); if(nBytes == SOCKET_ERROR) { //Recv failed diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 0070fed6..109d761c 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -20,10 +20,13 @@ namespace Oyster ~Connection(); virtual bool Connect( unsigned short port , const char serverName[] ); - virtual bool InitiateServer( unsigned short port ); + virtual bool InitiateServer( unsigned short port ); + virtual void Disconnect(); - virtual bool Send(const char message[]); - virtual int Recieve(char message[]); + + virtual bool Send(const unsigned char message[]); + virtual int Recieve(unsigned char message[]); + virtual int Listen(); private: diff --git a/Code/Network/NetworkDependencies/IConnection.h b/Code/Network/NetworkDependencies/IConnection.h index 1443b781..91b7c7b4 100644 --- a/Code/Network/NetworkDependencies/IConnection.h +++ b/Code/Network/NetworkDependencies/IConnection.h @@ -14,8 +14,8 @@ namespace Oyster public: virtual void Disconnect() = 0; - virtual bool Send( const char message[] ) = 0; - virtual int Recieve(char message[]) = 0; + virtual bool Send( const unsigned char message[] ) = 0; + virtual int Recieve(unsigned char message[]) = 0; virtual bool InitiateServer( unsigned short port ) { return false; }; virtual int Listen() { return -1; }; virtual bool Connect( unsigned short port, const char serverName[] ) { return false; }; diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index 3f783790..e0bb75a1 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -32,6 +32,14 @@ namespace Oyster std::string textMessage; ProtocolTest() { this->packageType = package_type_test; } }; + /*struct Prutt + { + PackageType t; + union PRUTT + { + ProtocolTest *ptest, + }; + };*/ } } } diff --git a/Code/Network/OysterNetworkClient/Client.cpp b/Code/Network/OysterNetworkClient/Client.cpp index a32f0996..3569b7d4 100644 --- a/Code/Network/OysterNetworkClient/Client.cpp +++ b/Code/Network/OysterNetworkClient/Client.cpp @@ -19,12 +19,12 @@ bool Client::Connect(unsigned int port, char filename[]) return true; } -void Client::Send(char msg[]) +void Client::Send(unsigned char msg[]) { connection->Send(msg); } -void Client::Recv(char msg[]) +void Client::Recv(unsigned char msg[]) { connection->Recieve(msg); } \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/Client.h b/Code/Network/OysterNetworkClient/Client.h index e08d6348..a48e37d9 100644 --- a/Code/Network/OysterNetworkClient/Client.h +++ b/Code/Network/OysterNetworkClient/Client.h @@ -21,8 +21,8 @@ namespace Oyster bool Connect(unsigned int port, char filename[]); - void Send(char msg[]); - void Recv(char msg[]); + void Send(unsigned char msg[]); + void Recv(unsigned char msg[]); private: ::Oyster::Network::Connection* connection; diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index a6002d0a..5fa8fd0f 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -1,10 +1,14 @@ #include #include "Client.h" #include +#include "..\NetworkDependencies\Translator.h" + using namespace std; +using namespace Oyster::Network::Protocols;; using namespace Oyster::Network::Client; #pragma comment(lib, "ws2_32.lib") + void ShutdownSockets(); bool InitSockets(); void chat(Client client); @@ -23,7 +27,6 @@ int main() //Connect to server client.Connect(9876, "10.0.0.3"); - chat(client); //Recieve message @@ -51,31 +54,58 @@ void ShutdownSockets() void chat(Client client) { - char msgRecv[255] = "\0"; - char msgSend[255] = "\0"; + Oyster::Network::Translator *t = new Oyster::Network::Translator(); + + unsigned char msgRecv[255] = "\0"; + string msgSend = ""; + + ProtocolHeader header; + ProtocolTest test; bool chatDone = false; while(!chatDone) { client.Recv(msgRecv); + + header = t->Translate(msgRecv); - cout<< "Client 2: " << msgRecv << endl; - - cin.getline(msgSend , 255 , '\n'); - - if(strlen(msgSend) < 1) + switch(header.packageType) { - strcpy_s(msgSend , " "); + case package_type_header: + break; + + case package_type_test: + cout <<"Client 2: " <<((ProtocolTest*)&header)->textMessage <Translate(test); + + client.Send(message); } else diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp index f86d37b8..8c2bdd0d 100644 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ b/Code/Network/OysterNetworkServer/Client.cpp @@ -12,12 +12,12 @@ Client::~Client() delete connection; } -void Client::Send(char buffer[]) +void Client::Send(unsigned char buffer[]) { connection->Send(buffer); } -void Client::Recv(char buffer[]) +void Client::Recv(unsigned char buffer[]) { connection->Recieve(buffer); } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h index 2d1de909..05215b31 100644 --- a/Code/Network/OysterNetworkServer/Client.h +++ b/Code/Network/OysterNetworkServer/Client.h @@ -20,8 +20,8 @@ namespace Oyster Client(unsigned int socket); ~Client(); - void Send(char buffer[]); - void Recv(char buffer[]); + void Send(unsigned char buffer[]); + void Recv(unsigned char buffer[]); private: ::Oyster::Network::Connection* connection; diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index a399dc62..e20cb584 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -59,7 +59,7 @@ int main() Client client2(clientSocket); cout << "Second client connected." << endl; - client1.Send("Hej"); + client1.Send((unsigned char*) "Hej"); while(1) {