int main(int argc, char* argv[])
{
    title("Testing Sockets", '=');

    try
    {
        //Verbose v(true);
        SocketSystem ss;
        SocketConnecter si;
        SocketListener sl(9070, Socket::IP6);
        ClientHandler cp;
        sl.start(cp);
        while (!si.connect("localhost", 9070))
        {
            Verbose::show("client waiting to connect");
            ::Sleep(100);
        }

        title("Starting string test on client");
        clientTestStringHandling(si);
        title("Starting buffer test on client");
        clientTestBufferHandling(si);

        si.sendString("TEST_STOP");

        Verbose::show("\n  client calling send shutdown\n");
        si.shutDownSend();
    }
    catch (std::exception& ex)
    {
        Verbose::show("  Exception caught:", always);
        Verbose::show(std::string("\n  ") + ex.what() + "\n\n");
    }
}
void Sendr::Send()
{
	SocketSystem ss;
	SocketConnecter si;					//create socketConnector
	
	Message msg_ = sendQ_.deQ();

	std::string MsgHeader = msg_.getHeader();
	std::string cmd = msg_.getCommand();
	std::string sourceIP = msg_.getsrcIP();
	size_t sourcePort = msg_.getsrcPort();
	std::string filepath = msg_.getFilePath();
	for (size_t i = 0; i < msg_.getdstPort().size(); i++)
	{
		std::string destIP = msg_.getdstIP()[i];
		size_t destPort = msg_.getdstPort()[i];
		msg_.addAttrib(Attr("DESTIP", destIP));
		msg_.addAttrib(Attr("DESTPORT", std::to_string(destPort)));
		while (!si.connect(destIP, destPort))			//connect to destPort - server
		{
			std::cout << "Client waiting to connect \n";
			::Sleep(100);
		}
		std::cout << "\nClient is connected to the server - Port : " << destPort << "\n";
		if (cmd.compare("FILE_UPLOAD") == 0)
			sendFile(si, msg_);							//build and send message over socket
		else if (cmd.compare("FILE_DOWNLOAD") == 0)
			sendDownloadMsg(si, msg_);
		else if (cmd.compare("FILE_SEARCH") == 0)
			sendFileSearchMsg(si, msg_);
		else if (cmd.compare("TEXT_SEARCH") == 0)
			sendTxtSearchMsg(si, msg_);
	}
}
Пример #3
0
int main()
{
  title("Testing Sender package ", '=');

  try
  {
	Sender sender;
    Verbose v(true);
    SocketSystem ss;
    SocketConnecter si;
	Message msg;
    while (!si.connect("localhost", 9085))
    {
      Verbose::show("client waiting to connect");
      ::Sleep(100);
    }
	// TODO sent
	msg.commandType = UPLOAD;
	msg.senderPort = 9080;
	msg.destAdd = "localhost";
	msg.destPort = 9085;
	msg.fileName = "demo.txt";
	sender.sendFiledata(si, msg, true);
	Verbose::show("\n  client calling send shutdown\n");
    si.shutDownSend();
  }
  catch (std::exception& ex)
  {
    Verbose::show("  Exception caught:", always);
    Verbose::show(std::string("\n  ") + ex.what() + "\n\n");
  }
}
//----< Test Stub to test the sender>--------------------------------
int main() {
	title("Message Passing Communication", '=');
	try
	{
		Sender s;
		Verbose v(true);
		SocketSystem ss;
		SocketConnecter si;
		while (!si.connect("localhost", 9080))
		{
			Verbose::show("client waiting to connect");
			::Sleep(100);
		}

		title("Starting string test on client");
		std::vector<std::string> messageDetails;
		messageDetails.push_back("upload");
		messageDetails.push_back("localhost");
		messageDetails.push_back("9080");
		messageDetails.push_back("Delay.pdf");
		messageDetails.push_back("localhost");
		messageDetails.push_back("9081");

		s.clientFileHandling(si, messageDetails, "input/");
		si.shutDownSend();
	}
	catch (std::exception& ex)
	{
		Verbose::show("Exception caught:", always);
		Verbose::show(std::string("\n  ") + ex.what() + "\n\n");
	}
}
Пример #5
0
void MsgClient::execute(const size_t TimeBetweenMessages, const size_t NumMessages)
{
  // send NumMessages messages
  
  ClientCounter counter;
  size_t myCount = counter.count();
  std::string myCountString = Utilities::Converter<size_t>::toString(myCount);

  Show::attach(&std::cout);
  Show::start();

  Show::title(
    "Starting HttpMessage client" + myCountString + 
    " on thread " + Utilities::Converter<std::thread::id>::toString(std::this_thread::get_id())
  );
  try
  {
    SocketSystem ss;
    SocketConnecter si;
    while (!si.connect("localhost", 8080))
    {
      Show::write("\n client waiting to connect");
      ::Sleep(100);
    }
    HttpMessage msg;
	//test for upload files
	sendFolder(si);
	//test for upload dependency
	sendDependency(si);
	// send message to check out get all the list of files
	//sendGetFolderList(si);
	//readMessage(si);
	//test for get file

	std::string path = "../Repository/SunMay11903202016";
	sendDownloadWithout(si,path);
	::Sleep(200);
	receiveFile(si);
	receiveFile(si);
	Show::write("\n\n  client sent\n" + msg.toIndentedString());

    msg = makeMessage(1, "quit", "toAddr:localhost:8080");
    sendMessage(msg, si);
    Show::write("\n\n  client" + myCountString + " sent\n" + msg.toIndentedString());
    Show::write("\n");
    Show::write("\n  All done folks");
  }
  catch (std::exception& exc)
  {
    Show::write("\n  Exeception caught: ");
    std::string exMsg = "\n  " + std::string(exc.what()) + "\n\n";
    Show::write(exMsg);
  }
}
//----< interpret sending message >-----------------
void Sender::interpretingSendingMessage(Message& msg)
{
	string command = msg.getCommand();
	map<string, string> att = msg.getAttributes();
	string destIP = att["destIP"];
	int destPort = atoi(att["destPort"].c_str());
	try{
		displayLine('=');
		Verbose v(true);
		SocketSystem ss;
		SocketConnecter si;
		BlockingQueue<Message> sQueue;
		while (!si.connect(destIP, destPort))
		{
			Verbose::show("client waiting to connect");
			::Sleep(100);
		}
		if (command == "STRING_HANDLING_REQUEST")
		{
			displayString("Demonstrating: Sending string to one peer to other peer");
			displayLine(' ');
			stringHandlingRequest(si, msg);
		}
		if (command == "STRING_HANDLING_REPLY")
		{
			displayString("Demonstrating: Reply from one peer to other peer - String Received");
			displayLine(' ');
			stringHandlingReply(si, msg);
		}
		if (command == "FILE_HANDLING_REQUEST")
		{
			displayString("Demonstrating: Sending file to one peer to other peer");
			displayLine(' ');
			fileHandlingRequest(si, msg);
		}
		if (command == "FILE_HANDLING_REPLY")
		{
			displayString("Demonstrating: Reply from one peer to other peer - File Received");
			displayLine(' ');
			fileHandlingReply(si, msg);
		}
		si.shutDownSend();
	}
	catch (std::exception& ex){
		Verbose::show("  Exception caught:", always);
		Verbose::show(std::string("\n  ") + ex.what() + "\n\n");
	}
	displayLine('-');
}
void Sendr::sendAck(std::string sourceIp, size_t sourcePort, std::string destIp, size_t destPort)
{
	SocketSystem ss;
	SocketConnecter si;

	while (!si.connect(destIp, destPort))
	{
		std::cout << "Client waiting to connect \n";
		::Sleep(100);
	}
	si.sendString("ACKNOWLEDGE");
	std::string ack_str = "Acknowledgement from server..";
	si.sendString(ack_str);
	std::cout << "\n---------------------------------";
	std::cout << "\ndestIP   :: " << destIp;
	std::cout << "\ndestPort :: " << destPort << "\n";
	std::cout << "Sending Acknowledgement.....\n";
	std::cout << "-------------------------------\n";
}
// --------------------  This Function sends the requested file to the client and checks if the dependencies need to be sent--------------------
void Server::sendServerFiles(HttpMessage msg)
{	
	SocketSystem ss;
	SocketConnecter si;
	std::string cPort = msg.findValue("From-Port");
	int ClientPort = Converter<int>::toValue(cPort);	
	while (!si.connect("localhost", ClientPort))
	{
		::Sleep(100);
	}																					// Searches for the revlevant folder and then sends the file
	Sender send;	
	std::string DepsFlag = msg.findValue("ExtractWithDepsFlag");
	std::string fileToSend = msg.findValue("file");
	std::string path;	
	std::vector<std::string> dirs = FileSystem::Directory::getDirectories("./ServerDrive", fileToSend+"*");	
	if (dirs.size() == 0)
		Show::write("No such file present in the repository => " + fileToSend + "\n");
	if (dirs.size() == 1)
	{
		std::vector<std::string> files = FileSystem::Directory::getFiles("./ServerDrive/" + dirs[0], fileToSend + "*");
	    Show::write("\n Sending File :: " + files[0] + " to Client @: " + cPort);
		send.sendFile("./ServerDrive/" + dirs[0] + "/" + files[0], si, getServerPort(), ClientPort);
		path = "./ServerDrive/" + dirs[0] + "/";
		if (DepsFlag == "Yes")
			sendFileDependencies(msg, path,si);
	}
	if (dirs.size() > 1)
	{
		std::string latest_dir = getLatestDir(dirs,fileToSend);
		std::vector<std::string> files = FileSystem::Directory::getFiles("./ServerDrive/" + latest_dir, fileToSend + "*");
		Show::write("\n Sending File :: " + files[0] + " to Client @: " + cPort);
		send.sendFile("./ServerDrive/" + latest_dir + "/" + files[0], si , getServerPort(), ClientPort);
		path = "./ServerDrive/" + latest_dir + "/";
		if (DepsFlag == "Yes")
			sendFileDependencies(msg, path,si);
	}
	msg = makeMessage(1, "quit", "toAddr:localhost:"+cPort);
	send.sendMessage(msg, si);
}
Пример #9
0
int main(int argc, char* argv[])
{
  Show::attach(&std::cout);
  Show::start();
  Show::title("Testing Sockets", '=');

  try
  {
    SocketSystem ss;
    SocketConnecter si;
    SocketListener sl(9070, Socket::IP6);
    ClientHandler cp;
    sl.start(cp);
    while (!si.connect("localhost", 9070))
    {
      Show::write("\n  client waiting to connect");
      ::Sleep(100);
    }

    Show::title("Starting string test on client");
    clientTestStringHandling(si);
    Show::title("Starting buffer test on client");
    clientTestBufferHandling(si);

    si.sendString("TEST_STOP");

    Show::write("\n\n  client calling send shutdown\n");
    si.shutDownSend();
    sl.stop();
  }
  catch (std::exception& ex)
  {
    std::cout << "\n  Exception caught:";
    std::cout << "\n  " << ex.what() << "\n\n";
  }
}