Fixed merge errors

This commit is contained in:
Pontus Fransson 2013-11-22 09:17:07 +01:00
parent 954a1ac669
commit 5265fd1af1
5 changed files with 88 additions and 7 deletions

View File

@ -26,8 +26,8 @@ bool Connection::Connect(unsigned short port , const char serverName[])
} }
struct hostent *hostEntry; struct hostent *hostEnt;
if((hostEntry = gethostbyname(serverName)) == NULL) if((hostEnt = gethostbyname(serverName)) == NULL)
{ {
//couldn't find host //couldn't find host
return false; return false;
@ -35,7 +35,7 @@ bool Connection::Connect(unsigned short port , const char serverName[])
struct sockaddr_in server; struct sockaddr_in server;
server.sin_family = AF_INET; server.sin_family = AF_INET;
server.sin_port = htons(port); 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) while(1)
{ {
@ -77,7 +77,7 @@ bool Connection::InitiateServer(unsigned short port)
return false; 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) if(listen(mySocket, 5) == SOCKET_ERROR)
{ {
//"Listen failed! //"Listen failed!
@ -98,7 +98,13 @@ bool Connection::Send(const unsigned char message[])
{ {
int nBytes; int nBytes;
unsigned long messageSize = strlen((char*)message); unsigned long messageSize = strlen((char*)message);
<<<<<<< HEAD
if((nBytes = send(mySocket, (char*)message , messageSize, 0)) == SOCKET_ERROR) 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! //Send failed!
return false; return false;

View File

@ -21,9 +21,17 @@ namespace Oyster
virtual bool Connect( unsigned short port , const char serverName[] ); 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 void Disconnect();
<<<<<<< HEAD
virtual bool Send(const unsigned char message[]); virtual bool Send(const unsigned char message[]);
virtual int Recieve(char unsigned message[]); virtual int Recieve(char unsigned message[]);
=======
virtual bool Send(const unsigned char message[]);
virtual int Recieve(unsigned char message[]);
>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af
virtual int Listen(); virtual int Listen();
private: private:

View File

@ -32,6 +32,14 @@ namespace Oyster
std::string textMessage; std::string textMessage;
ProtocolTest() { this->packageType = package_type_test; } ProtocolTest() { this->packageType = package_type_test; }
}; };
/*struct Prutt
{
PackageType t;
union PRUTT
{
ProtocolTest *ptest,
};
};*/
} }
} }
} }

View File

@ -1,10 +1,14 @@
#include <iostream> #include <iostream>
#include "Client.h" #include "Client.h"
#include <WinSock2.h> #include <WinSock2.h>
#include "..\NetworkDependencies\Translator.h"
using namespace std; using namespace std;
using namespace Oyster::Network::Protocols;;
using namespace Oyster::Network::Client; using namespace Oyster::Network::Client;
#pragma comment(lib, "ws2_32.lib") #pragma comment(lib, "ws2_32.lib")
void ShutdownSockets(); void ShutdownSockets();
bool InitSockets(); bool InitSockets();
void chat(Client client); void chat(Client client);
@ -29,9 +33,13 @@ int main()
unsigned char* recvBuffer = new unsigned char[255]; unsigned char* recvBuffer = new unsigned char[255];
<<<<<<< HEAD
client.Send(recvBuffer); client.Send(recvBuffer);
//chat(client); //chat(client);
=======
chat(client);
>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af
//Recieve message //Recieve message
//client.Recv(msgRecv); //client.Recv(msgRecv);
@ -58,8 +66,18 @@ void ShutdownSockets()
void chat(Client client) void chat(Client client)
{ {
<<<<<<< HEAD
unsigned char msgRecv[255] = "\0"; unsigned char msgRecv[255] = "\0";
unsigned char msgSend[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; bool chatDone = false;
@ -67,8 +85,19 @@ void chat(Client client)
{ {
client.Recv(msgRecv); client.Recv(msgRecv);
cout<< "Client 2: " << msgRecv << endl; header = t->Translate(msgRecv);
switch(header.packageType)
{
case package_type_header:
break;
case package_type_test:
cout <<"Client 2: " <<((ProtocolTest*)&header)->textMessage <<endl;
break;
}
<<<<<<< HEAD
cin.getline((char*)msgSend , 255 , '\n'); cin.getline((char*)msgSend , 255 , '\n');
if(strlen((char*)msgSend) < 1) if(strlen((char*)msgSend) < 1)
@ -81,8 +110,34 @@ void chat(Client client)
if(strlen((char*)msgSend) < 1) if(strlen((char*)msgSend) < 1)
{ {
memcpy(msgSend, "ERROR", 1); memcpy(msgSend, "ERROR", 1);
=======
std::getline(std::cin, msgSend);
std::cin.clear();
if(msgSend.length() < 1)
{
//memcpy(msgSend, " " , 1);
msgSend = " ";
//strcpy_s((char)msgSend , " ");
} }
client.Send(msgSend);
if( msgSend != "exit")
{
if(msgSend.length() < 1)
{
//memcpy(msgSend, "ERROR" , 5);
msgSend = "ERROR!";
//strcpy_s(msgSend, "ERROR");
>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af
}
test.packageType = package_type_test;
test.size = msgSend.length();
test.textMessage = msgSend;
unsigned char *message = t->Translate(test);
client.Send(message);
} }
else else

View File

@ -40,8 +40,12 @@ int main()
Client client2(clientSocket); Client client2(clientSocket);
cout << "Second client connected." << endl; cout << "Second client connected." << endl;
<<<<<<< HEAD
client1.Send((unsigned char*)"Hej"); client1.Send((unsigned char*)"Hej");
ProtocolHeader* header = NULL; ProtocolHeader* header = NULL;
=======
client1.Send((unsigned char*) "Hej");
>>>>>>> 4142688f6c4a63aa97341205588ad6cace0f43af
while(1) while(1)
{ {