在PHP中关闭客户端套接字的问题

时间:2019-03-09 04:36:40

标签: php websocket plc

我试图编写一个与PLC通信的PHP项目,但是当我关闭套接字客户端时遇到了问题,它没有立即关闭,当我调用AJAX函数重新加载值时连接的设备增加了,有人帮我? I use RS_sim to simulate PLC

my page

我用于创建和关闭套接字客户端的代码:

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";}

0 个答案:

没有答案