-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_recv_client.php
66 lines (51 loc) · 1.34 KB
/
test_recv_client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
// Data Relay Center example PHP client.
// (C) 2019 CubicleSoft. All Rights Reserved.
if (!isset($_SERVER["argc"]) || !$_SERVER["argc"])
{
echo "This file is intended to be run from the command-line.";
exit();
}
// Temporary root.
$rootpath = str_replace("\\", "/", dirname(__FILE__));
require_once $rootpath . "/support/sdk_drc_client.php";
$drc = new DRCClient();
// Connect to the server.
// Note that the origin must be in the origins list or the call will fail with a 403 Forbidden response.
$result = $drc->Connect("ws://127.0.0.1:7328", "http://127.0.0.1");
if (!$result["success"])
{
var_dump($result);
exit();
}
// Join the channel.
$result = $drc->JoinChannel("Test-Channel", "test-client", false, true);
if (!$result["success"])
{
var_dump($result);
exit();
}
$channel = $result["data"]["channel"];
$clientid = $drc->GetClientID();
echo "Connected as client ID " . $clientid . "\n";
// Main loop.
$result = $drc->Wait();
while ($result["success"])
{
do
{
$result = $drc->Read();
if (!$result["success"]) break;
if ($result["data"] !== false)
{
// Do something with the data.
echo "Raw message from server:\n";
var_dump($result["data"]);
echo "\n";
}
} while ($result["data"] !== false);
$result = $drc->Wait();
}
// An error occurred.
var_dump($result);
?>