From 816dced937fb8e301d4ed28066064ffa97b194c7 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Tue, 19 Nov 2013 14:21:25 +0100 Subject: [PATCH] Chat test server --- .../NetworkDependencies/Connection.cpp | 2 +- .../OysterNetworkClient/ClientMain.cpp | 2 +- Code/Network/OysterNetworkServer/Client.cpp | 5 +++++ Code/Network/OysterNetworkServer/Client.h | 1 + .../OysterNetworkServer/ServerMain.cpp | 21 ++++++++++++++++--- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index b07e6106..9639329f 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -126,7 +126,7 @@ int Connection::Recieve(char message[]) return -1; } - message[nBytes] = NULL; + message[nBytes] = '\0'; return 1; } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index ac38ead1..0c89410b 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -31,7 +31,7 @@ int main() //print message //cout << msgRecv << endl; - ShutdownSockets(); + ShutdownSockets(); system("pause"); return 0; diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp index 7c15984d..50ce3b8c 100644 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ b/Code/Network/OysterNetworkServer/Client.cpp @@ -13,4 +13,9 @@ Client::~Client() void Client::Send(char buffer[]) { connection->Send(buffer); +} + +void Client::Recv(char buffer[]) +{ + connection->Recieve(buffer); } \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h index c72c7669..3c29c620 100644 --- a/Code/Network/OysterNetworkServer/Client.h +++ b/Code/Network/OysterNetworkServer/Client.h @@ -14,6 +14,7 @@ public: ~Client(); void Send(char buffer[]); + void Recv(char buffer[]); private: diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 0fb81776..626e91bb 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -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();