Created
April 23, 2013 10:53
-
-
Save GeeH/5442628 to your computer and use it in GitHub Desktop.
How the hell do you unit test this???
This file contains hidden or 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 | |
/** | |
* Gary Hockin | |
* 23/04/2013 | |
*/ | |
namespace FAFSServer\Service; | |
class FAFSServer | |
{ | |
/** | |
* @var array | |
*/ | |
protected $config; | |
/** | |
* @param array $config | |
*/ | |
public function __construct(array $config) | |
{ | |
$this->config = $config; | |
} | |
public function start() | |
{ | |
// get config values (or use some sane defaults) | |
$ip = isset($this->config['ip']) ? $this->config['ip'] : '127.0.0.1'; | |
$port = isset($this->config['port']) ? $this->config['port'] : '6610'; | |
$length = isset($this->config['maxLength']) ? $this->config['maxLength'] : 1024; | |
// Create socket server | |
$socket = stream_socket_server("udp://$ip:$port", $errorNo, $errorMessage, STREAM_SERVER_BIND); | |
if ($errorNo || $errorMessage || get_resource_type($socket) !== 'stream') { | |
throw new \Exception("Error creating server: $errorMessage", $errorNo); | |
} | |
// Loop through data as it's received | |
while ($data = stream_socket_recvfrom($socket, $length, null, $receivedFrom)) { | |
echo "$data \r\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment