Fixed merge errors
This commit is contained in:
parent
954a1ac669
commit
5265fd1af1
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -32,6 +32,14 @@ namespace Oyster
|
|||
std::string textMessage;
|
||||
ProtocolTest() { this->packageType = package_type_test; }
|
||||
};
|
||||
/*struct Prutt
|
||||
{
|
||||
PackageType t;
|
||||
union PRUTT
|
||||
{
|
||||
ProtocolTest *ptest,
|
||||
};
|
||||
};*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#include <iostream>
|
||||
#include "Client.h"
|
||||
#include <WinSock2.h>
|
||||
#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 <<endl;
|
||||
break;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
cin.getline((char*)msgSend , 255 , '\n');
|
||||
|
||||
if(strlen((char*)msgSend) < 1)
|
||||
|
@ -81,8 +110,34 @@ void chat(Client client)
|
|||
if(strlen((char*)msgSend) < 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 , " ");
|
||||
}
|
||||
|
||||
if( msgSend != "exit")
|
||||
{
|
||||
if(msgSend.length() < 1)
|
||||
{
|
||||
//memcpy(msgSend, "ERROR" , 5);
|
||||
msgSend = "ERROR!";
|
||||
//strcpy_s(msgSend, "ERROR");
|
||||
>>>>>>> 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
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue