.reference

git-svn-id: svn://ultimatepp.org/upp/trunk@11328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2017-09-18 09:44:58 +00:00
parent 0ae2cfecc0
commit 9c9972dcda
5 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,47 @@
#include <Core/Core.h>
using namespace Upp;
// Clients are run in blocking mode
void ClientEmulation()
{
Thread::Start([] {
#if 0 // change to 1 to dome single request
Sleep(500);
WebSocket ws;
ws.Connect("ws://127.0.0.1:12321");
if(ws.IsError()) {
LOG("Failed to connect");
return;
}
LOG("Client Request");
ws.SendText(AsString(Random()));
LOG("Response: " << ws.Receive());
ws.Close();
#else
for(;;) {
Sleep(Random(2000));
Thread::Start([] {
LOG("Started a new client");
WebSocket ws;
ws.Connect("ws://127.0.0.1:12321");
if(ws.IsError()) {
LOG("Failed to connect");
return;
}
LOG("WebSocket connected to the server");
while(Random(20) && ws.IsOpen()) {
String request = AsString(Random());
LOG("Sending request " << request);
ws.SendText(request);
String reply = ws.Receive();
LOG(request << " -> " << reply);
Sleep(Random(2000));
}
ws.Close();
});
}
#endif
});
}