giúp đỡ em sữa code này lại ạ



  • mọi người giúp e sữa code này lại cho nó chạy multi client server được không ạ. e sửa mãi mà không được
    ...............................
    from Tkinter import *
    from socket import *
    from threading import *
    from ScrolledText import*
    class Receive():
    def init(self, server, gettext):
    #Thread.init(self)
    self.server = server
    self.gettext = gettext
    while 1:
    try:
    text = self.server.recv(1024)
    if not text: break
    self.gettext.configure(state=NORMAL)
    self.gettext.insert(END,'client >> %s\n'%text)
    self.gettext.configure(state=DISABLED)
    self.gettext.see(END)
    except:
    break
    class App(Thread):
    server = socket()
    server.bind(('localhost', input("Port: ")))
    server.listen(5)
    client,addr = server.accept()
    def init(self, master):
    Thread.init(self)
    frame = Frame(master)
    frame.pack()
    self.gettext = ScrolledText(frame, height=10,width=100, state=NORMAL)
    self.gettext.pack()
    sframe = Frame(frame)
    sframe.pack(anchor='w')
    self.pro = Label(sframe, text="Server>>");
    self.sendtext = Entry(sframe,width=80)
    self.sendtext.focus_set()
    self.sendtext.bind(sequence="<Return>", func=self.Send)
    self.pro.pack(side=LEFT)
    self.sendtext.pack(side=LEFT)
    self.gettext.insert(END,'Welcome to Chat\n')
    self.gettext.configure(state=DISABLED)
    def Send(self, args):
    self.gettext.configure(state=NORMAL)
    text = self.sendtext.get()
    if text=="": text=" "
    self.gettext.insert(END,'Me >> %s \n'%text)
    self.sendtext.delete(0,END)
    self.client.send(text)
    self.sendtext.focus_set()
    self.gettext.configure(state=DISABLED)
    self.gettext.see(END)
    def run(self):
    Receive(self.client, self.gettext)
    root = Tk()
    root.title('Server Chat')
    app = App(root).start()
    root.mainloop()


Log in to reply
 

Looks like your connection to Cộng đồng Python Việt Nam was lost, please wait while we try to reconnect.