我有两个按钮。连接和断开连接。当第一次按下连接时,客户端成功连接到服务器(localhost:4106),当按下断开连接时,客户端断开连接。我的问题是,当我再次按“连接”时,客户端将不会重新连接到服务器,并且我收到一条错误消息:http: //i.imgur.com/dkvos.png
我认为这是因为套接字连接不能被重用?有解决方法吗?谢谢
#!/usr/bin/python
import socket
import Tkinter
import tkMessageBox
top = Tkinter.Tk()
s = socket.socket()
host = '127.0.0.1'
port = 4106
def connect():
s.connect((host, port))
def disconnect():
s.close()
ConnectBtn = Tkinter.Button(top, text ="Connect", command = connect)
DisconnectBtn = Tkinter.Button(top, text ="Disconnect", command = disconnect)
ConnectBtn.pack()
DisconnectBtn.pack()
top.mainloop()