Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pardons Julien
committed
Sep 22, 2013
1 parent
3f5736e
commit 8ca9503
Showing
3 changed files
with
147 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
class WebSocket { | ||
|
||
private static $sock = null; | ||
|
||
public function __call($name, $arguments) { | ||
\eTools\Utils\Logger::error("Call undefined method $name " . print_r($arguments, true)); | ||
} | ||
|
||
public function open() { | ||
|
||
} | ||
|
||
public function __construct($url) { | ||
$this->url = str_replace("ws://", "http://", $url); | ||
preg_match("!^http://(.*):(\d+)/(.*)$!", $this->url, $match); | ||
$this->ip = $match[1]; | ||
$this->port = $match[2] + 1; | ||
$this->scope = $match[3]; | ||
\eTools\Utils\Logger::log("Setting WebSocket fix to " . $this->ip . ":" . $this->port); | ||
|
||
if (self::$sock == null) | ||
self::$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); | ||
} | ||
|
||
public function sendData($data_string) { | ||
$msg = json_encode(array("scope" => $this->scope, "data" => $data_string)); | ||
$len = strlen($msg); | ||
socket_sendto(self::$sock, $msg, $len, 0, $this->ip, $this->port); | ||
} | ||
|
||
public function send($data_string) { | ||
$msg = json_encode(array("scope" => $this->scope, "data" => $data_string)); | ||
$len = strlen($msg); | ||
socket_sendto(self::$sock, $msg, $len, 0, $this->ip, $this->port); | ||
} | ||
|
||
} | ||
|
||
?> |
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