Perl-如何知道套接字客户端何时断开连接(当用户关闭窗口/浏览器时)

时间:2014-11-15 03:03:03

标签: html5 perl sockets websocket

我正在使用HTML 5和Perl Web服务器套接字。套接字服务器可以知道用户何时关闭浏览器?请帮忙 服务器:

  Net::WebSocket::Server->new(
    listen => 8080,
    on_connect => sub {
        my ($serv, $conn) = @_;
        $conn->on(
            utf8 => sub {
                my ($conn, $msg) = @_;
                $conn->send_utf8($msg);
            },
        disconnect => sub {
        my ($conn, $code, $reason) = @_;
        $conn->disconnect();
    },
        );
    },
)->start;

1 个答案:

答案 0 :(得分:1)

是。在套接字上为the disconnect event设置处理程序:

$conn->on(
    disconnect => sub {
        my ($conn, $code, $reason) = @_;
        ...
    },
 );