Skip to content

Commit

Permalink
gets possible client Local Address
Browse files Browse the repository at this point in the history
  • Loading branch information
ch3k1 committed Nov 29, 2016
1 parent f242861 commit 3676292
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
9 changes: 4 additions & 5 deletions lib/bin/server.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
<?php

require dirname(__DIR__) . '/vendor/autoload.php';

$ipaddress = isset($_SERVER['SERVER_ADDR'])?$_SERVER['SERVER_ADDR']:gethostbyname(gethostname());
$address = new SquidApp\Request();
$loop = React\EventLoop\Factory::create();
$pusher = new SquidApp\Pusher;


// Listen for the web server to make a ZeroMQ push after an ajax request
$context = new React\ZMQ\Context($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555'); // Binding to 127.0.0.1 means the only client that can connect is itself
$pull->on('message', array($pusher, 'onBlogEntry'));
$pull->on('message', array($pusher, 'onNetworkEntry'));

// Set up our WebSocket server for clients wanting real-time updates
$webSock = new React\Socket\Server($loop);
$webSock->listen(8080, $ipaddress); // Binding to 0.0.0.0 means remotes can connect
$webSock->listen(8080, $address->getClientAddress()); // Binding to 0.0.0.0 means remotes can connect
$webServer = new Ratchet\Server\IoServer(
new Ratchet\Http\HttpServer(
new Ratchet\WebSocket\WsServer(
Expand Down
4 changes: 3 additions & 1 deletion lib/src/SquidApp/Pusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ public function onSubscribe(ConnectionInterface $conn, $topic) {

}

public function onBlogEntry($entry) {
public function onNetworkEntry($entry) {

$db = new Database();

$entryData = json_decode($entry, true);

print_r($entryData);

if (!array_key_exists($entryData['squidmagic'] , $this->subscribedTopics)) {
return;
Expand Down
22 changes: 22 additions & 0 deletions lib/src/SquidApp/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace SquidApp;

/**
* Gets client Address.
*/
class Request
{
public $address;

public function __construct($address = null)
{
$this->address = $address;
}

public function getClientAddress()
{
$this->address = isset($_SERVER['SERVER_ADDR'])?$_SERVER['SERVER_ADDR']:gethostbyname(gethostname());
return $this->address;
}
}

0 comments on commit 3676292

Please sign in to comment.