local sock = ngx.socket.tcp() connect then send and receive...if sock.is_closed() then do something here...end