处理rtmp.py公司

2024-09-24 02:25:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我当前正在使用rtmp.py公司对于RTMP实时流服务器。它工作得很好,但是一天有好几次,一个可能连接不良的人会腾空并留下插座。整个服务器都关闭了,更糟的是关闭服务器。Killcx甚至连连接都不碰。这显然不理想。虽然套接字仍然绑定到(例如/live1),但其他用户不能使用此装入点。在

该项目在Github上可用于源代码视图。我对Python非常陌生,在我的研究中,我相信客户机连接很困难,这会导致close()失败。我试着找开发人员帮忙,但没有成功。如果有人能帮我实现一个补丁,我会很乐意将它提交到项目页面,希望它也能让其他人受益。在

rtmp.py source

如果你需要我提供更多信息,请告诉我。提前谢谢!在


Tags: 项目用户pygithub服务器源代码公司插座
1条回答
网友
1楼 · 发布于 2024-09-24 02:25:37

造物主向我伸出援手。对于将来可能有这个问题的用户,我提供了一个对我有用的答案。对运行(self)进行了以下更改:中的定义rtmp.py公司. 根据个人喜好调整值或按原样使用。评论为“第106期”。在

def run(self):
try:
    while True:
        sock, remote = (yield multitask.accept(self.sock))  # receive client TCP
        if sock == None:
            if _debug: print 'rtmp.Server accept(sock) returned None.'
            break
        if _debug: print 'connection received from', remote
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) # make it non-block
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) # Issue #106
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 10) # Issue #106
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 10) # Issue #106
        sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 2) # Issue #106
        client = Client(sock, self)
except GeneratorExit: pass # terminate
except:
    if _debug: print 'rtmp.Server exception ', (sys and sys.exc_info() or None)

if (self.sock):
    try: self.sock.close(); self.sock = None
    except: pass
if (self.queue):
    yield self.queue.put((None, None))
    self.queue = None

相关问题 更多 >