0
ここでは、インスタンスが初期化されるときにソケットを初期化するのが混乱し、ループを使ってデータを転送するために使用します。Pythonソケットエラー:ソケットではないオブジェクト
class Server2:
host = "localhost"
port = 44444
s = ""
sock = ""
addr = ""
def __init__(self,voitingSistem,voitingInterfece,voiting,sql):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.s.bind((self.host, self.port))
self.s.listen(5)
self.sock, self.addr =self.s.accept()
self.client = WorkWithClient()
self.voitingSistem = voitingSistem()
self.voitingInterfece = voitingInterfece()
self.voiting = Voiting("d")
super().__init__()
def mainLoop(self):
while True:
buf = self.sock.recv(1024) # receive and decode a command
print("getting command: "+(buf.decode('utf8')))
ansver = self.client.AcceptCommand(buf.decode('utf8')) # act upon the command
if buf.decode('utf8') == "exit":
self.sock.send("bye")
break
elif buf:
self.sock.send(buf)
print(buf.decode('utf8'))
self.sock.close()
エラー:
An attempt was made to perform an operation on an object that is not a socket
これはどのラインですか? –
プログラムは最初のデータを受信します。しかし、そのような間違いでデータの次のビットがクラッシュします。 – Dmitry
コードをペーストに正しくインデントしてください。 (mainLoopの前に4つのスペースがありません)。また、stacktrace全体を手伝ってくれるでしょう。 –