External Exam Download Resources Web Applications Games Recycle Bin

ReservationClient.cpp

------------------------------------
Reservation Client Main Project File
------------------------------------*/

#include "stdafx.h"
#include "TcpClient.h"

int main(array<System::String ^> ^args){
	String^ request;
	TcpConsole client;
	//if the client cannot connect:
	if(!client.connect())return 0;
	//get connecting messages:
	client.read_block();
	while (true) //connected:
		{
		client.menu_options();		
		//get initial choice:
		request = Console::ReadLine();
		//quit:
		if (request->ToUpper()->Equals ("Q")){
			//let the server know:
			client.writer->WriteLine("DISCONNECT");
			client.writer->Flush();
			break;
		}
		else client.prepare_request(request); //invoke method that decides how to handle request
		try	{client.send_request(); //send outgoing request
			 client.process_response(); //receive and process incoming request
			}
		catch (IOException^){break;} // incase connection is lost
	}
	return 0;
}