几次后sock.recv超时

时间:2015-10-01 18:28:18

标签: python python-2.7 sockets

这是我连接服务器的功能(在我的情况下,是Samsung Smart TV,它是一个远程应用程序),然后该功能正在观看是否通过sock.recv()连接到TV ok:

def connection(self):

        sock.connect((self.entry_tvip.get(), 55000))
        sock.send(part1)
        sock.send(part2)
        sock.settimeout(1)

        self.tvappstring = app.entry_tvappstring.get()
        self.connection_status()


    def connection_status(self):

        if sock.recv(1024) == "":

            print("Status: Disconnected")
            self.label_connection_status['text'] = 'Status: Disconnected'
            self.label_connection_status['fg'] = 'red'
        else:

            print("Status: Connected")
            self.label_connection_status['text'] = 'Status: Connected'
            self.label_connection_status['fg'] = 'green'

        self.master.after(random.randint(1000, 3000), self.connection_status)

但几次之后它就把这个错误输给了我,它停止了工作:

Status: Connected #The apps print
Status: Connected #The apps print
Exception in Tkinter callback #error
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
    return self.func(*args)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 586, in callit
    func(*args)
  File "remote_new.py", line 90, in connection_status
    if sock.recv(1024) == "":
timeout: timed out

0 个答案:

没有答案