Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » request: Socket working example
Re: request: Socket working example [message #23693 is a reply to message #23643] Sun, 15 November 2009 13:34 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13979
Registered: November 2005
Ultimate Member
#include <Web/Web.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	Socket server;
	if(!ServerSocket(server, 3214)) {
		Cout() << "Unable to initialize server socket!\n";
		SetExitCode(1);
		return;
	}
	Cout() << "Waiting for requests..\n";
	for(;;) {
		Socket s;
		if(server.Accept(s)) {
			String w = s.ReadUntil('\n');
			Cout() << "Request: " << w << '\n';
			if(w == "time")
				s.Write(AsString(GetSysTime()));
			else
				s.Write(AsString(3 * atoi(~w)));
			s.Write("\n");
		}
	}
}


#include <Web/Web.h>

using namespace Upp;

String Request(const String& r)
{
	Socket s;
	if(!ClientSocket(s, CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 3214)) {
		Cout() << "Unable to connect to server!\n";
		SetExitCode(1);
		return Null;
	}
	s.Write(r + '\n');
	return s.ReadUntil('\n');
}

CONSOLE_APP_MAIN
{
	Cout() << Request("time") << '\n';
	Cout() << Request("33") << '\n';
}


(It is now in reference too).
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Is there a simple CGI library developed with U++?
Next Topic: UDP sockets?
Goto Forum:
  


Current Time: Sun May 12 22:22:11 CEST 2024

Total time taken to generate the page: 0.02958 seconds