我想写一个继承socket
所以我的代码如下:
class walkie_talkie(socket.socket(socket.AF_INET, socket.SOCK_STREAM)):
def __init__(self):
self.BUFFERSIZE = 8192
self.STATE = None
self.IP = None # Server IP
self.PORT = 5000
self.NUMBER_OF_UNACCEPTED_CONNECTIONS = 1
self.bytestream = None
super().__init__()
我将此类用作:
from walkie_talkie import walkie_talkie
rpi1 = walkie_talkie()
所以我认为使用super().__init__()
继承了socket.socket(socket.AF_INET, socket.SOCK_STREAM)
的功能
但是,我收到此错误:
File "...\lib\socket.py", line 151, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
TypeError: an integer is required (got type str)
有人可以告诉我如何使用超级功能吗? 预先感谢!
编辑:解决方案
我纠正了我的错误:
class walkie_talkie(socket.socket):
def __init__(self):
self.BUFFERSIZE = 8192
self.STATE = None
self.IP = None # Server IP
self.PORT = 5000
self.NUMBER_OF_UNACCEPTED_CONNECTIONS = 1
self.bytestream = None
super().__init__(socket.AF_INET, socket.SOCK_STREAM)