Chat test server

This commit is contained in:
Pontus Fransson 2013-11-19 14:21:25 +01:00
parent 1df11becf7
commit 816dced937
5 changed files with 26 additions and 5 deletions

View File

@ -126,7 +126,7 @@ int Connection::Recieve(char message[])
return -1;
}
message[nBytes] = NULL;
message[nBytes] = '\0';
return 1;
}

View File

@ -31,7 +31,7 @@ int main()
//print message
//cout << msgRecv << endl;
ShutdownSockets();
ShutdownSockets();
system("pause");
return 0;

View File

@ -13,4 +13,9 @@ Client::~Client()
void Client::Send(char buffer[])
{
connection->Send(buffer);
}
void Client::Recv(char buffer[])
{
connection->Recieve(buffer);
}

View File

@ -14,6 +14,7 @@ public:
~Client();
void Send(char buffer[]);
void Recv(char buffer[]);
private:

View File

@ -13,6 +13,8 @@ int main()
{
cout << "Server" << endl;
char recvBuffer[255];
if(!InitSockets())
{
cout << "Sockets failed to initialize" << endl;
@ -23,13 +25,26 @@ int main()
listener.Init(9876);
//Start listening
//Accept a client
int clientSocket = listener.Accept();
Client client1(clientSocket);
cout << "First client connected." << endl;
//Accept a client
Client client(clientSocket);
clientSocket = listener.Accept();
Client client2(clientSocket);
cout << "Second client connected." << endl;
//Send a message to that client
client.Send("asd");
client1.Send("Hej");
while(1)
{
client1.Recv(recvBuffer);
client2.Send(recvBuffer);
client2.Recv(recvBuffer);
client1.Send(recvBuffer);
}
ShutdownSockets();