I have this simple server-client project. Its connect and I can get data from server but only first time. If I try to get data again it stops. Can anyone help me, whats wrong with my code?
def getMessage(self,clSocket):
clSocket.send(self.input.get().encode("ASCII"))
messageFromServer=clSocket.recv(128)
messagebox.showinfo("answer", messageFromServer)
def main():
serverName="localhost"
serverPort=11000
clientSocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clientSocket.connect((serverName,serverPort))
root = tk.Tk()
app = client(root,clientSocket)
root.mainloop()
if __name__ == '__main__':
main()
答案 0 :(得分:0)
Firstly you have not got enough code for it to work accurately, and you do not have a repeater, so it works by connecting it and sending across a message, then because it has not repeater to keep the connection open, it cuts the connection. Edit: Your code has zero functionality as you are only putting the client code up and asking us to build you a functioning project. You have to give us your attempt to build a server so it can latch onto it. Also for you localhost, you can simply replace it with socket.gethostname() and that will work for the local host.