-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket_server_2.php
More file actions
31 lines (22 loc) · 821 Bytes
/
socket_server_2.php
File metadata and controls
31 lines (22 loc) · 821 Bytes
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
<?php
// php socket_server.php
require __DIR__ . '/vendor/autoload.php';
$timer = 0;
$socket = new React\Socket\SocketServer('127.0.0.1:8082');
echo "Server running : tcp://127.0.0.1:8082";
$socket->on('connection', function ($connection) {
echo "\n\nconnection established\n";
echo "Remote address is : \n", $connection->getRemoteAddress();
$connection->on('data', function ($data) use ($connection) {
echo "\n\n--------------------------------------------------";
echo "\nReceived from CLIENT : $data\n";
$connection->write("You said: $data");
});
// Handle connection close
$connection->on('close', function () {
echo "Connection closed\n";
});
});
$socket->on('error', function (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
});