我试图编写一个与PLC通信的PHP项目,但是当我关闭套接字客户端时遇到了问题,它没有立即关闭,当我调用AJAX函数重新加载值时连接的设备增加了,有人帮我? I use RS_sim to simulate PLC
我用于创建和关闭套接字客户端的代码:
private function connect(){
// Create a protocol specific socket
if ($this->socket_protocol == "TCP"){
// TCP socket
$this->sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
}
$result = @socket_connect($this->sock, $this->host, $this->port);
if ($result === false) {
throw new Exception("socket_connect() failed.</br>Reason: ($result)".
socket_strerror(socket_last_error($this->sock)));
} else {
$this->status .= "Connected\n";
return true;
}}
private function disconnect(){
socket_close($this->sock);
$this->status .= "Disconnected\n";}