-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added swoole_server::heartbeat() no close connection.
- Loading branch information
Showing
3 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
<?php | ||
$ifs = swoole_get_local_ip(); | ||
if (isset($ifs['eth0'])) | ||
{ | ||
$server_ip = $ifs['eth0']; | ||
} | ||
else | ||
{ | ||
die("Step-0 failed. Error: swoole_get_local_ip() failed."); | ||
} | ||
echo "-------------------------------------------------------------\n"; | ||
echo "Swoole Unit Tests. ServerIP: {$server_ip}\n"; | ||
echo "-------------------------------------------------------------\n"; | ||
/** | ||
* UnitTests for swoole server. | ||
* This is just a client. Server see examples/server.php | ||
*/ | ||
|
||
$i = 0; | ||
$client = new swoole_client(SWOOLE_TCP); | ||
|
||
if (!$client->connect('127.0.0.1', 9501)) | ||
if (!$client->connect($server_ip, 9501)) | ||
{ | ||
echo "Step-1: failed. Error: connect to server failed.\n"; | ||
echo "Step-".$i++.": failed. Error: connect to server failed.\n"; | ||
} | ||
else | ||
{ | ||
if (!$client->send("hello")) | ||
{ | ||
echo "Step-2: failed. Error: send to server failed.\n"; | ||
echo "Step-".$i++.": failed. Error: send to server failed.\n"; | ||
} | ||
$data = $client->recv(); | ||
if (!$data) | ||
{ | ||
echo "Step-3: failed. Error: send to server failed.\n"; | ||
echo "Step-".$i++.": failed. Error: send to server failed.\n"; | ||
} | ||
else if ($data != "Swoole: hello") | ||
{ | ||
echo "Step-4: failed. Error: recv error data.\n"; | ||
echo "Step-".$i++.": failed. Error: recv error data.\n"; | ||
} | ||
else | ||
{ | ||
echo "TCP-Test-OK\n"; | ||
} | ||
} | ||
|
||
if (!$client->close()) | ||
{ | ||
echo "Step-8: failed. Error: close failed.\n"; | ||
echo "Step-".$i++.": failed. Error: close failed.\n"; | ||
} | ||
echo "-------------------------------------------------------------\n"; | ||
$client = new swoole_client(SWOOLE_UDP); | ||
$client->connect($server_ip, 9502); | ||
$client->send("hello"); | ||
$data = $client->recv(); | ||
if (!$data) | ||
{ | ||
echo "Step-".$i++.": failed. Error: send to server failed.\n"; | ||
} | ||
else if ($data != "Swoole: hello") | ||
{ | ||
echo "Step-".$i++.": failed. Error: recv error data.\n"; | ||
} | ||
else | ||
{ | ||
echo "UDP-Test-OK\n"; | ||
} | ||
echo "-------------------------------------------------------------\n"; | ||
echo "UnitTest Finish.\n"; |