// DemoClient.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <tchar.h> #include "MyClient.h" #include "protocol.h" int _tmain(int argc, _TCHAR* argv[]) { TCPSocket::initializeWinsock(); CMyClient client; string serverIP; int port; string alias; cout << "input server ip:" << endl; cin >> serverIP; cout << "input server port:" << endl; cin >> port; cout << "input client alias:" << endl; cin >> alias; client.Alias(alias); if (!client.connect(serverIP.c_str(), port)) { cout << "Unable to connect" <<endl; cout << "Tape to quit." <<endl; char ch; cin >> ch; return 0; } while (true) { cout << "tape q to quit, h for possible commands" << endl; char ch; cin >> ch; if (ch == 'q') { break; } if (ch == 'h') { cout << "e: sends a message to be echoed back.\nr: sends a message to be routed to a chosen recipient.\nb: broadcasts a message to evry client present on the server." << endl; } if (ch == 'e') { string message; cout << "input message:" << endl; cin >> message; EchoRequest request; request.set_msg(message); client.sendRequest(&request); } if (ch == 'r') { string message; cout << "input message:" << endl; cin >> message; string recipient; cout << "input recipient:" << endl; cin >> recipient; RoutedMessageRequest request; request.set_recipient(recipient); request.set_msg(message); client.sendRequest(&request); } if (ch == 'b') { string message; cout << "input message:" << endl; cin >> message; GroupMessageRequest request; request.set_msg(message); client.sendRequest(&request); } } return 0; }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)