Chat test server
This commit is contained in:
parent
1df11becf7
commit
816dced937
|
@ -126,7 +126,7 @@ int Connection::Recieve(char message[])
|
|||
return -1;
|
||||
}
|
||||
|
||||
message[nBytes] = NULL;
|
||||
message[nBytes] = '\0';
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -14,3 +14,8 @@ void Client::Send(char buffer[])
|
|||
{
|
||||
connection->Send(buffer);
|
||||
}
|
||||
|
||||
void Client::Recv(char buffer[])
|
||||
{
|
||||
connection->Recieve(buffer);
|
||||
}
|
|
@ -14,6 +14,7 @@ public:
|
|||
~Client();
|
||||
|
||||
void Send(char buffer[]);
|
||||
void Recv(char buffer[]);
|
||||
|
||||
|
||||
private:
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue