-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.class.php
More file actions
41 lines (34 loc) · 889 Bytes
/
socket.class.php
File metadata and controls
41 lines (34 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
class Socket
{
private $socket;
private $connected = false;
public function __construct($adresse, $port)
{
try {
$this->socket = stream_socket_client('tcp://'. $adresse . ':' . $port);
$this->connected = true;
} catch (Exception $e) {
$this->connected = false;
die();
}
}
function isConnected() {
return $this->connected;
}
function sendMessageToSocket($message)
{
$resultat = false;
if ($this->socket) {
$sent = stream_socket_sendto($this->socket, $message);
if ($sent > 0) {
$resultat = true;
}
$this->connected = false;
} else {
$resultat = false;
}
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
return $resultat;
}
}