From 1df11becf7a37134fd45524f758d872038a0dbd1 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Tue, 19 Nov 2013 14:18:34 +0100 Subject: [PATCH] chat test with server created simple chat program for the client to be able to chat between client through a server --- .../NetworkDependencies/Connection.cpp | 2 + .../OysterNetworkClient/ClientMain.cpp | 39 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 6fb70057..b07e6106 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -126,6 +126,8 @@ int Connection::Recieve(char message[]) return -1; } + message[nBytes] = NULL; + return 1; } diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index a3058900..ac38ead1 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -6,6 +6,7 @@ using namespace std; void ShutdownSockets(); bool InitSockets(); +void chat(Client client); int main() { @@ -19,13 +20,16 @@ int main() Client client; //Connect to server - client.Connect(9876, "127.0.0.1"); + client.Connect(9876, "10.0.0.3"); + + + chat(client); //Recieve message - client.Recv(msgRecv); + //client.Recv(msgRecv); //print message - cout << msgRecv << endl; + //cout << msgRecv << endl; ShutdownSockets(); @@ -42,4 +46,33 @@ bool InitSockets() void ShutdownSockets() { WSACleanup(); +} + +void chat(Client client) +{ + char msgRecv[255] = "\0"; + char msgSend[255] = "\0"; + + bool chatDone = false; + + while(!chatDone) + { + client.Recv(msgRecv); + + cout<< "Server: " << msgRecv << endl; + + cin.getline(msgSend , 255 , '\n'); + + if(msgSend != "exit") + { + client.Send(msgSend); + } + + else + { + chatDone = true; + } + + } + } \ No newline at end of file