Last active
December 29, 2015 23:19
-
-
Save payden/7741837 to your computer and use it in GitHub Desktop.
php-ws example
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
<?php | |
$ws = new WebSocketServer(); | |
$ws->bind("0.0.0.0", "8080"); | |
$ws->onopen = function($client) { | |
echo "New connection: " . $client->sockfd . "\n"; | |
}; | |
$ws->onclose = function($client) { | |
echo "Closing connection: " . $client->sockfd . "\n"; | |
}; | |
$ws->onmessage = function($client, $msg) { | |
echo "Received message: '" . $msg->payload . "'\n"; | |
echo "Echoing it back...\n"; | |
$client->sendText($msg->payload); | |
}; | |
$ws->run(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment