From 5265fd1af1ca9ede422228adc2e0c4f0e6cca8bf Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Fri, 22 Nov 2013 09:17:07 +0100 Subject: [PATCH] Fixed merge errors --- .../NetworkDependencies/Connection.cpp | 14 +++-- Code/Network/NetworkDependencies/Connection.h | 10 +++- Code/Network/NetworkDependencies/Protocols.h | 8 +++ .../OysterNetworkClient/ClientMain.cpp | 59 ++++++++++++++++++- .../OysterNetworkServer/ServerMain.cpp | 4 ++ 5 files changed, 88 insertions(+), 7 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index c84d3344..bddfe850 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! @@ -98,7 +98,13 @@ bool Connection::Send(const unsigned char message[]) { int nBytes; unsigned long messageSize = strlen((char*)message); +<<<<<<< HEAD if((nBytes = send(mySocket, (char*)message , messageSize, 0)) == SOCKET_ERROR) +======= + messageSize = 18; + nBytes = send(mySocket, (char*)message , messageSize, 0); + if(nBytes == SOCKET_ERROR) +>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af { //Send failed! return false; diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 5febafa5..3246f431 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -20,10 +20,18 @@ 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(); +<<<<<<< HEAD virtual bool Send(const unsigned char message[]); virtual int Recieve(char unsigned message[]); +======= + + virtual bool Send(const unsigned char message[]); + virtual int Recieve(unsigned char message[]); + +>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af virtual int Listen(); private: 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/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 2e6a4bfe..a558e7f5 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); @@ -29,9 +33,13 @@ int main() unsigned char* recvBuffer = new unsigned char[255]; +<<<<<<< HEAD client.Send(recvBuffer); //chat(client); +======= + chat(client); +>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af //Recieve message //client.Recv(msgRecv); @@ -58,17 +66,38 @@ void ShutdownSockets() void chat(Client client) { +<<<<<<< HEAD unsigned char msgRecv[255] = "\0"; unsigned char msgSend[255] = "\0"; +======= + Oyster::Network::Translator *t = new Oyster::Network::Translator(); + + unsigned char msgRecv[255] = "\0"; + string msgSend = ""; + + ProtocolHeader header; + ProtocolTest test; +>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af bool chatDone = false; while(!chatDone) { client.Recv(msgRecv); + + header = t->Translate(msgRecv); - cout<< "Client 2: " << msgRecv << endl; + switch(header.packageType) + { + case package_type_header: + break; + case package_type_test: + cout <<"Client 2: " <<((ProtocolTest*)&header)->textMessage <>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af } - client.Send(msgSend); + + test.packageType = package_type_test; + test.size = msgSend.length(); + test.textMessage = msgSend; + + unsigned char *message = t->Translate(test); + + client.Send(message); } else diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index a75c4228..2f301c63 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -40,8 +40,12 @@ int main() Client client2(clientSocket); cout << "Second client connected." << endl; +<<<<<<< HEAD client1.Send((unsigned char*)"Hej"); ProtocolHeader* header = NULL; +======= + client1.Send((unsigned char*) "Hej"); +>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af while(1) {