Click here to Skip to main content
15,881,757 members
Articles / Web Development / HTML

Server Wizard

Rate me:
Please Sign up or sign in to vote.
4.83/5 (6 votes)
1 Feb 2013CPOL7 min read 31K   1.9K   33  
A Visual C++ Project Wizard for the fast creation of high performance TCP servers in C++
// 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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Tunisia Tunisia
Services:
http://www.pushframework.com/?page_id=890

Comments and Discussions