- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocket.php
More file actions
Latest commit
52 lines (42 loc) · 870 Bytes
/
Copy pathsocket.php
File metadata and controls
52 lines (42 loc) · 870 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
42
43
44
45
46
47
48
49
50
51
52
<?php
class socket {
private$socket = null;
private$host = '';
private$port = 0;
publicfunctionhost($host) {
$this->host = $host;
return$this;
}
publicfunctionport($port) {
$this->port = $port;
return$this;
}
publicfunctionreceive() {
$data = '';
while ($str = fread($this->socket, 1024)) {
$data .= $str;
if (mb_strlen($str) < 1024) {
break;
}
}
return$data;
}
publicfunctionsend($data) {
fputs($this->socket, $data . "\r\n");
return$this;
}
publicfunctionexchange($data) {
$this->send($data);
$this->receive();
return$this;
}
publicfunctionsocket($host, $port) {
$this->host = $host;
$this->port = $port;
$this->socket = fsockopen($host, $port);
}
publicstaticfunctionfactory($host, $port) {
returnnewsocket($host, $port);
}
}
?>