Chat test server
This commit is contained in:
parent
1df11becf7
commit
816dced937
|
@ -126,7 +126,7 @@ int Connection::Recieve(char message[])
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
message[nBytes] = NULL;
|
message[nBytes] = '\0';
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,3 +14,8 @@ void Client::Send(char buffer[])
|
||||||
{
|
{
|
||||||
connection->Send(buffer);
|
connection->Send(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::Recv(char buffer[])
|
||||||
|
{
|
||||||
|
connection->Recieve(buffer);
|
||||||
|
}
|
|
@ -14,6 +14,7 @@ public:
|
||||||
~Client();
|
~Client();
|
||||||
|
|
||||||
void Send(char buffer[]);
|
void Send(char buffer[]);
|
||||||
|
void Recv(char buffer[]);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -13,6 +13,8 @@ int main()
|
||||||
{
|
{
|
||||||
cout << "Server" << endl;
|
cout << "Server" << endl;
|
||||||
|
|
||||||
|
char recvBuffer[255];
|
||||||
|
|
||||||
if(!InitSockets())
|
if(!InitSockets())
|
||||||
{
|
{
|
||||||
cout << "Sockets failed to initialize" << endl;
|
cout << "Sockets failed to initialize" << endl;
|
||||||
|
@ -23,13 +25,26 @@ int main()
|
||||||
listener.Init(9876);
|
listener.Init(9876);
|
||||||
|
|
||||||
//Start listening
|
//Start listening
|
||||||
|
//Accept a client
|
||||||
int clientSocket = listener.Accept();
|
int clientSocket = listener.Accept();
|
||||||
|
Client client1(clientSocket);
|
||||||
|
cout << "First client connected." << endl;
|
||||||
|
|
||||||
//Accept a client
|
//Accept a client
|
||||||
Client client(clientSocket);
|
clientSocket = listener.Accept();
|
||||||
|
Client client2(clientSocket);
|
||||||
|
cout << "Second client connected." << endl;
|
||||||
|
|
||||||
//Send a message to that client
|
client1.Send("Hej");
|
||||||
client.Send("asd");
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
client1.Recv(recvBuffer);
|
||||||
|
client2.Send(recvBuffer);
|
||||||
|
|
||||||
|
client2.Recv(recvBuffer);
|
||||||
|
client1.Send(recvBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
ShutdownSockets();
|
ShutdownSockets();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue