mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-27 06:19:34 -06:00
.reference
git-svn-id: svn://ultimatepp.org/upp/trunk@11328 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
0ae2cfecc0
commit
9c9972dcda
5 changed files with 148 additions and 0 deletions
47
reference/AsyncWebSocket/Client.cpp
Normal file
47
reference/AsyncWebSocket/Client.cpp
Normal 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
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue