Pull MiscBranch
This commit is contained in:
parent
f02a67b9b1
commit
43b111f0d3
|
@ -37,7 +37,7 @@ int Connection::InitiateServer(unsigned short port)
|
||||||
{
|
{
|
||||||
int errorCode = 0;
|
int errorCode = 0;
|
||||||
|
|
||||||
if((errorCode = initiateSocket()) != 0)
|
if((errorCode = InitiateSocket()) != 0)
|
||||||
{
|
{
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,7 @@ int Connection::InitiateServer(unsigned short port)
|
||||||
|
|
||||||
int Connection::InitiateClient()
|
int Connection::InitiateClient()
|
||||||
{
|
{
|
||||||
int errorCode;
|
return InitiateSocket();
|
||||||
return initiateSocket();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Connection::Disconnect()
|
int Connection::Disconnect()
|
||||||
|
@ -80,7 +78,7 @@ int Connection::Disconnect()
|
||||||
return WSAGetLastError();
|
return WSAGetLastError();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Connection::Send(OysterByte& bytes)
|
int Connection::Send(OysterByte& bytes)
|
||||||
{
|
{
|
||||||
int nBytes;
|
int nBytes;
|
||||||
|
|
||||||
|
@ -129,7 +127,7 @@ int Connection::Listen()
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
//Private functions
|
//Private functions
|
||||||
///////////////////////////////////////
|
///////////////////////////////////////
|
||||||
int Connection::initiateSocket()
|
int Connection::InitiateSocket()
|
||||||
{
|
{
|
||||||
this->socket = ::socket(AF_INET, SOCK_STREAM, 0);
|
this->socket = ::socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if(this->socket == SOCKET_ERROR)
|
if(this->socket == SOCKET_ERROR)
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace Oyster
|
||||||
virtual int InitiateServer( unsigned short port );
|
virtual int InitiateServer( unsigned short port );
|
||||||
virtual int InitiateClient();
|
virtual int InitiateClient();
|
||||||
|
|
||||||
virtual bool Send( OysterByte& bytes );
|
virtual int Send( OysterByte& bytes );
|
||||||
virtual int Recieve( OysterByte& bytes );
|
virtual int Recieve( OysterByte& bytes );
|
||||||
|
|
||||||
virtual int Disconnect();
|
virtual int Disconnect();
|
||||||
|
@ -31,7 +31,7 @@ namespace Oyster
|
||||||
virtual int Listen();
|
virtual int Listen();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int initiateSocket();
|
int InitiateSocket();
|
||||||
|
|
||||||
int socket;
|
int socket;
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Oyster
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual int Disconnect() = 0;
|
virtual int Disconnect() = 0;
|
||||||
virtual bool Send( OysterByte& bytes ) = 0;
|
virtual int Send( OysterByte& bytes ) = 0;
|
||||||
virtual int Recieve( OysterByte& bytes) = 0;
|
virtual int Recieve( OysterByte& bytes) = 0;
|
||||||
virtual int InitiateServer( unsigned short port ) { return false; };
|
virtual int InitiateServer( unsigned short port ) { return false; };
|
||||||
virtual int InitiateClient() { return false; };
|
virtual int InitiateClient() { return false; };
|
||||||
|
|
|
@ -116,7 +116,7 @@ void MessageHeader::PackFloat(float i[], unsigned int elementCount, OysterByte&
|
||||||
PackUnsignedInt(elementCount, bytes);
|
PackUnsignedInt(elementCount, bytes);
|
||||||
|
|
||||||
//Pack all elements
|
//Pack all elements
|
||||||
for(int j = 0; j < elementCount; j++)
|
for(int j = 0; j < (int)elementCount; j++)
|
||||||
{
|
{
|
||||||
PackFloat(i[j], bytes);
|
PackFloat(i[j], bytes);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ float* MessageHeader::UnpackFloat(unsigned int& elementCount, OysterByte& bytes)
|
||||||
elementCount = UnpackUnsignedInt(bytes);
|
elementCount = UnpackUnsignedInt(bytes);
|
||||||
|
|
||||||
i = new float[elementCount];
|
i = new float[elementCount];
|
||||||
for(int j = 0; j < elementCount; j++)
|
for(int j = 0; j < (int)elementCount; j++)
|
||||||
{
|
{
|
||||||
i[j] = UnpackFloat(bytes);
|
i[j] = UnpackFloat(bytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ MessageTest::~MessageTest()
|
||||||
void MessageTest::Pack(ProtocolHeader& header, OysterByte& bytes)
|
void MessageTest::Pack(ProtocolHeader& header, OysterByte& bytes)
|
||||||
{
|
{
|
||||||
MessageHeader::Pack(header, bytes);
|
MessageHeader::Pack(header, bytes);
|
||||||
unsigned char asd[1000];
|
|
||||||
//strcpy_s(asd, bytes.GetSize(), bytes);
|
|
||||||
|
|
||||||
PackStr(static_cast<ProtocolTest*>(&header)->textMessage, bytes);
|
PackStr(static_cast<ProtocolTest*>(&header)->textMessage, bytes);
|
||||||
PackFloat(static_cast<ProtocolTest*>(&header)->f, static_cast<ProtocolTest*>(&header)->numOfFloats, bytes);
|
PackFloat(static_cast<ProtocolTest*>(&header)->f, static_cast<ProtocolTest*>(&header)->numOfFloats, bytes);
|
||||||
|
|
|
@ -84,7 +84,7 @@ void OysterByte::IncreaseCapacity(unsigned int oldSize)
|
||||||
capacity = size * 2;
|
capacity = size * 2;
|
||||||
unsigned char* temp = new unsigned char[capacity];
|
unsigned char* temp = new unsigned char[capacity];
|
||||||
|
|
||||||
for(int i = 0; i < oldSize; i++)
|
for(int i = 0; i < (int)oldSize; i++)
|
||||||
{
|
{
|
||||||
temp[i] = byteArray[i];
|
temp[i] = byteArray[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace Oyster
|
||||||
//floating point (32, 64-bit)
|
//floating point (32, 64-bit)
|
||||||
void Pack(unsigned char buffer[], float i)
|
void Pack(unsigned char buffer[], float i)
|
||||||
{
|
{
|
||||||
int tempFloat = Pack754(i, 32, 8);
|
__int64 tempFloat = Pack754(i, 32, 8);
|
||||||
Pack(buffer, tempFloat);
|
Pack(buffer, tempFloat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -269,7 +269,7 @@ namespace Oyster
|
||||||
float Unpackf(unsigned char buffer[])
|
float Unpackf(unsigned char buffer[])
|
||||||
{
|
{
|
||||||
int tempFloat = Unpacki(buffer);
|
int tempFloat = Unpacki(buffer);
|
||||||
return Unpack754(tempFloat, 32, 8);
|
return (float)Unpack754(tempFloat, 32, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Unpackd(unsigned char buffer[])
|
double Unpackd(unsigned char buffer[])
|
||||||
|
|
|
@ -34,4 +34,6 @@ std::wstring GetErrorMessage(int errorCode)
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Added this if bufLen is 0
|
||||||
|
return retVal;
|
||||||
}
|
}
|
|
@ -50,7 +50,7 @@ int main()
|
||||||
test.numOfFloats = 35;
|
test.numOfFloats = 35;
|
||||||
test.f = new float[test.numOfFloats];
|
test.f = new float[test.numOfFloats];
|
||||||
float temp = 395.456f;
|
float temp = 395.456f;
|
||||||
for(int i = 0; i < test.numOfFloats; i++)
|
for(int i = 0; i < (int)test.numOfFloats; i++)
|
||||||
{
|
{
|
||||||
test.f[i] = temp;
|
test.f[i] = temp;
|
||||||
temp--;
|
temp--;
|
||||||
|
@ -67,7 +67,7 @@ int main()
|
||||||
t.Unpack(set, recvBuffer);
|
t.Unpack(set, recvBuffer);
|
||||||
cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl;
|
cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl;
|
||||||
cout << "Client1: " << set->Protocol.pTest->textMessage << endl;
|
cout << "Client1: " << set->Protocol.pTest->textMessage << endl;
|
||||||
for(int i = 0; i < set->Protocol.pTest->numOfFloats; i++)
|
for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++)
|
||||||
{
|
{
|
||||||
cout << set->Protocol.pTest->f[i] << ' ';
|
cout << set->Protocol.pTest->f[i] << ' ';
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ int main()
|
||||||
t.Unpack(set, recvBuffer);
|
t.Unpack(set, recvBuffer);
|
||||||
cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl;
|
cout << set->Protocol.pTest->clientID << ' ' << set->Protocol.pTest->packageType << ' ' << set->Protocol.pTest->size << endl;
|
||||||
cout << "Client2: " << set->Protocol.pTest->textMessage << endl;
|
cout << "Client2: " << set->Protocol.pTest->textMessage << endl;
|
||||||
for(int i = 0; i < set->Protocol.pTest->numOfFloats; i++)
|
for(int i = 0; i < (int)set->Protocol.pTest->numOfFloats; i++)
|
||||||
{
|
{
|
||||||
cout << set->Protocol.pTest->f[i] << ' ';
|
cout << set->Protocol.pTest->f[i] << ' ';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue