Skip to content

Commit c115034

Browse files
committed
PHP class: reviewed formatting (removed trailing spaces, replaced 4 spaces with tabs)
1 parent 433a37a commit c115034

File tree

1 file changed

+48
-47
lines changed

1 file changed

+48
-47
lines changed

bridge/php/bridgeclient.class.php

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,55 +21,56 @@
2121
error_reporting(E_ERROR);
2222

2323
class bridgeclient {
24-
25-
private $service_port = 5700;
26-
private $address = "127.0.0.1";
27-
private $socket;
28-
29-
private function connect() {
30-
($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
31-
|| die("socket_create() failed: " . socket_strerror(socket_last_error()) . "\n");
32-
socket_set_option($this->socket,SOL_SOCKET, SO_RCVTIMEO, array("sec"=>3, "usec"=>0));
33-
socket_connect($this->socket, $this->address, $this->service_port)
34-
|| die("socket_connect() failed: " . socket_strerror(socket_last_error($this->socket)) . "\n");
35-
}
36-
37-
private function disconnect() {
38-
socket_close($this->socket);
39-
}
4024

41-
private function sendcommand($command,$key,$value="") {
42-
$jsonreceive = "";
43-
$obraces=0;
44-
$cbraces=0;
25+
private $service_port = 5700;
26+
private $address = "127.0.0.1";
27+
private $socket;
28+
29+
private function connect() {
30+
($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))
31+
|| die("socket_create() failed: " . socket_strerror(socket_last_error()) . "\n");
32+
socket_set_option($this->socket,SOL_SOCKET, SO_RCVTIMEO, array("sec"=>3, "usec"=>0));
33+
socket_connect($this->socket, $this->address, $this->service_port)
34+
|| die("socket_connect() failed: " . socket_strerror(socket_last_error($this->socket)) . "\n");
35+
}
36+
37+
private function disconnect() {
38+
socket_close($this->socket);
39+
}
4540

46-
$this->connect();
47-
48-
$jsonsend = '{"command":"'.$command.'","key":"'.$key.'","value":"'.$value.'"}';
49-
socket_write($this->socket, $jsonsend, strlen($jsonsend));
50-
51-
do {
52-
socket_recv($this->socket, $buffer, 1,0);
53-
$jsonreceive.=$buffer;
54-
if($buffer == "{") $obraces++;
55-
if($buffer == "}") $cbraces++;
56-
} while ($obraces != $cbraces);
57-
58-
$this->disconnect();
59-
60-
$jsonarray=json_decode($jsonreceive);
61-
if ($jsonarray->{'value'} == NULL) $jsonarray->{'value'}="None";
62-
63-
return $jsonarray->{'value'};
64-
}
65-
66-
public function get($key) {
67-
return $this->sendcommand("get",$key);
68-
}
69-
70-
public function put($key,$value) {
71-
return $this->sendcommand("put",$key,$value);
72-
}
41+
private function sendcommand($command,$key,$value="") {
42+
$jsonreceive = "";
43+
$obraces=0;
44+
$cbraces=0;
45+
46+
$this->connect();
47+
48+
$jsonsend = '{"command":"'.$command.'","key":"'.$key.'","value":"'.$value.'"}';
49+
socket_write($this->socket, $jsonsend, strlen($jsonsend));
50+
51+
do {
52+
socket_recv($this->socket, $buffer, 1,0);
53+
$jsonreceive.=$buffer;
54+
if($buffer == "{") $obraces++;
55+
if($buffer == "}") $cbraces++;
56+
} while ($obraces != $cbraces);
57+
58+
$this->disconnect();
59+
60+
$jsonarray=json_decode($jsonreceive);
61+
if ($jsonarray->{'value'} == NULL) $jsonarray->{'value'}="None";
62+
63+
return $jsonarray->{'value'};
64+
}
65+
66+
public function get($key) {
67+
return $this->sendcommand("get",$key);
68+
}
69+
70+
public function put($key,$value) {
71+
return $this->sendcommand("put",$key,$value);
72+
}
7373

7474
}
7575
?>
76+

0 commit comments

Comments
 (0)