无法在python客户端套接字程序中找到错误

时间:2018-09-04 11:23:37

标签: python python-3.x sockets connection client

我想澄清一下。这可行。该程序连接到服务器,服务器仅发送欢迎消息,但是当服务器将消息发送回客户端时,它给了我这个错误。我无法弄清楚,我是套接字的新手,所以我试图从这个错误中学习。. entire 错误消息位于注释的底部

import socket

class client:
    def __init__(self,s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)):
        self.s = s

    def connect(self,server_ip = 'ip'): # i replaced the actual ip with 'ip' 
    for safety reasons (obviously)
        self.s.connect(('ip', 12345))
        while True:
           data = self.s.recv(1024).decode('utf-8')
           if not data:
               break
           print(data)
        self.s.close()

 if __name__ == '__main__':
 cl = client()
 cl.connect()

这是错误:

 Traceback (most recent call last):
 File "client.py", line 18, in <module>
   cl.connect()
 File "client.py", line 10, in connect
   data = self.s.recv(1024).decode('utf-8')
 OSError: [Errno 9] Bad file desscriptor

0 个答案:

没有答案