Home » Developing U++ » U++ Developers corner » Help needed with link errors (serversocket)
Re: Help needed with link errors (serversocket) [message #48514 is a reply to message #48510] |
Wed, 12 July 2017 11:43   |
Oblivion
Messages: 1226 Registered: August 2007
|
Senior Contributor |
|
|
Hello imos, and welcome!
Web package is depreceated. AFAIK, it is kept for historical reasons.
You can use TcpSocket for socket operations.
There is a client/server example in Examples section:
Server: http://www.ultimatepp.org/reference$SocketServer$en-us.html
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
TcpSocket server;
if(!server.Listen(3214, 5)) {
Cout() << "Unable to initialize server socket!\n";
SetExitCode(1);
return;
}
Cout() << "Waiting for requests..\n";
for(;;) {
TcpSocket s;
if(s.Accept(server)) {
String w = s.GetLine();
Cout() << "Request: " << w << " from: " << s.GetPeerAddr() << '\n';
if(w == "time")
s.Put(AsString(GetSysTime()));
else
s.Put(AsString(3 * atoi(~w)));
s.Put("\n");
}
}
}
Client: http://www.ultimatepp.org/reference$SocketClient$en-us.html
#include <Core/Core.h>
using namespace Upp;
String Request(const String& r)
{
TcpSocket s;
if(!s.Connect(CommandLine().GetCount() ? CommandLine()[0] : "127.0.0.1", 3214)) {
Cout() << "Unable to connect to server!\n";
SetExitCode(1);
return Null;
}
s.Put(r + '\n');
return s.GetLine();
}
// Start reference/SocketServer before starting this program
CONSOLE_APP_MAIN
{
Cout() << Request("time") << '\n';
Cout() << Request("33") << '\n';
}
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 12 July 2017 11:46] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Aug 25 19:02:09 CEST 2025
Total time taken to generate the page: 0.06258 seconds
|