class Chat(Tk.Frame): global server server = im.IMServerProxy('http://webdev.cs.manchester.ac.uk/' + '~intozcc8/IMServer.php') global clientsList clientsList = [] chatClients = 0 def __init__(self, parent, index): Tk.Frame.__init__(self, parent) self.parent = parent self.parent.title('CHAT') self.parent.withdraw() self.createClients(index) def createClients(self, index): global client client = Tk.Toplevel(self) client.geometry("300x500") print index global user user = createUser(self, client, index) toplevel = user.getClient() def readMessage(self, toplevel): userMessage = toplevel.inputBox.get("1.0", Tk.END) toplevel.inputBox.delete("1.0", Tk.END) if len(userMessage) > 1: global currentClients server[('messageClient' + str(index)).strip()] = "User " + str(index) \ + " message: " + userMessage if int(server['numberClients'][0:-2]) != int(currentClients): #print server['numberClients'][0:-2] #print currentClients currentClients = server['numberClients'][0:-2] print int(currentClients) for x in [ i for i in range(int(currentClients)) if i != (index - 1) ]: server[('readClient' + str(x + 1)).strip()] = \ server[('messageClient' + str(index)).strip()] toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, "You: " + userMessage + "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def writeMessage(self, messageWrite): toplevel = chat.getUser() toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, messageWrite.strip() + "\n") toplevel.messageBox.insert(Tk.END, "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def getClient(self): return client def getUser(self): return user.getClient()
class Chat(Tk.Frame): global server server = im.IMServerProxy( 'http://webdev.cs.manchester.ac.uk/~intozcc8/IMServer.php') global clientsList clientsList = [] global numberClients def __init__(self, parent, index): Tk.Frame.__init__(self, parent) self.parent = parent self.parent.title('CHAT') self.parent.withdraw() numberClient = index self.createClients(numberClient) def createClients(self, numberClients): global client client = Tk.Toplevel(self) client.geometry("300x500") global index index = numberClients print index global user user = createUser(self, client, index) toplevel = user.getClient() def readMessage(self, toplevel): userMessage = toplevel.inputBox.get("1.0", Tk.END) toplevel.inputBox.delete("1.0", Tk.END) if len(userMessage) > 1: server[('messageClient' + str(index)).strip( )] = "User " + str(index) + " message: " + userMessage toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, "You: " + userMessage + "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def writeMessage(self, index): toplevel = chat.getUser() toplevel.messageBox.configure(state="normal") userMessage = server[('messageClient' + str(index + 1)).strip()] toplevel.messageBox.insert(Tk.END, userMessage.strip() + "\n") toplevel.messageBox.insert(Tk.END, "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") time.sleep(0.30) server[('messageClient' + str(index + 1)).strip()] = "" def getClient(self): return client def getUser(self): return user.getClient()
class Chat(Tk.Frame): global server server = im.IMServerProxy( 'http://webdev.cs.manchester.ac.uk/~intozcc8/IMServer.php') global clientsList clientsList = [] global numberClients def __init__(self, parent): Tk.Frame.__init__(self, parent) self.parent = parent self.parent.title('CHAT') self.parent.withdraw() numberClients = int((server['numberClients']).strip()) self.createClients(numberClients) def createClients(self, numberClients): client = Tk.Toplevel(self) client.geometry("300x500") numberClients = numberClients + 1 server['numberClients'] = str(numberClients) createUser(self, client, numberClients) numberClients = numberClients + 1 server['numberClients'] = str(numberClients) def readMessage(self, toplevel, index, newClientList): userMessage = toplevel.inputBox.get("1.0", Tk.END) toplevel.inputBox.delete("1.0", Tk.END) if len(userMessage) > 1: server[('messageClient' + str(x + 1)).strip()] = userMessage self.writeMessage(toplevel, index, newClientList) toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, "You: " + userMessage + "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def writeMessage(self, sendTopLevel, index, newClientsList): for toplevel in newClientsList: if toplevel != sendTopLevel: toplevel.messageBox.configure(state="normal") userMessage = server[('messageClient' + str(x + 1)).strip()] toplevel.messageBox.insert( Tk.END, "User: "******" message :" + userMessage.strip() + "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def getClientList(chat): return clientsList
sys.stdout.write('User ' + str(x + 1) + ' message ' + server[('messageClient' + str(x + 1)).strip()]) sys.stdout.write('>>> ') sys.stdout.flush() server[('messageClient' + str(x + 1)).strip()] = '' except ValueError: server['numberClients'] = str(backUp) continue def openUser(): while True: with open(sys.argv[1], 'r') as file: for line in iter(file.readline, ''): a = 2 server = im.IMServerProxy('http://webdev.cs.manchester.ac.uk/~intozcc8/IMServer.php') userNumber = server['numberClients'] print 'User ' + userNumber time.sleep(1) t2 = Thread(target=openUser) t2.daemon = True t2.start() messagePrinted = False t1 = Thread(target=write) t1.daemon = True t1.start() backUp = server['numberClients'] t3 = Thread(target=read) t3.daemon = True t3.start() while True:
import im import time server = im.IMServerProxy( 'http://webdev.cs.manchester.ac.uk/~j47510pc/IMServer.php') def recursive(boool): if boool: print "User2: " + server['newKey'] myMessage = raw_input('Type your message: ') server['newKey'] = myMessage boool = True print "User1: " + server['newKey'] time.sleep(10) recursive(boool) server.clear() recursive(False)
import im import time import urllib import fnmatch server = im.IMServerProxy('http://webdev.cs.manchester.ac.uk/~w81454af/IMServer.php') def sendMessage(): server.__delitem__('message') if len(server.keys()) == 4: message = raw_input('Type your message here: ') server['message'] = message waitingForMessageUser2() def waitingForMessageUser2(): time.sleep(4) while server['message'] == '\r\n': print('waiting for message') time.sleep(2) print(server['message']) sendMessage() if len(server.keys()) == 1: server['state'] = '0'
import im import time import Tkinter from Tkinter import * import tkMessageBox # Create the window top = Tkinter.Tk() # Add a text box to the gui text = Text(top) text.pack(side=TOP) server = \ im.IMServerProxy('http://webdev.cs.manchester.ac.uk/~mbaxaar2/IMServer.php' ) # Check if there are any keys on the server areKeys = server.keys() # Add entry field e1 = Entry(top, bd=5) e1.config(state=DISABLED) e1.pack(side=LEFT) # Send a message state def sendMess(): text.config(state=NORMAL) text.insert(INSERT, 'Please type a message:\n') e1.config(state=NORMAL)
class Chat(Tk.Frame): global server server = im.IMServerProxy('http://webdev.cs.manchester.ac.uk/' + \ '~intozcc8/IMServer.php') global clientsList clientsList = [] chatClients = 0 def __init__(self, parent, index): Tk.Frame.__init__(self, parent) self.parent = parent self.parent.title('CHAT') self.parent.withdraw() self.createClients(index) def createClients(self, index): global client client = Tk.Toplevel(self) client.geometry("300x500") client.withdraw() print index global inputUserName inputUserName = Tk.Toplevel(self) inputUserName.geometry("300x60") inputUserName.mainLabel = Tk.Label(inputUserName, \ text="Choose your user name") inputUserName.mainLabel.pack() inputUserName.buttonEnter = Tk.Button(inputUserName, text='ENTER', \ width=5, command= lambda: self.createUserHelper(client, index)) inputUserName.buttonEnter.config(state="disabled") inputUserName.buttonEnter.pack(side='right') inputUserName.inputBox = Tk.Text(inputUserName, heigh=2, width=100) inputUserName.inputBox.pack() def createUserHelper(self, client, index): global user user = createUser(self, client, index) global toplevel toplevel = user.getClient() global varReady varReady.set(1) client.deiconify() inputUserName.withdraw() def readMessage(self, toplevel): userMessage = toplevel.inputBox.get("1.0", Tk.END) toplevel.inputBox.delete("1.0", Tk.END) if len(userMessage) > 1: global currentClients server[('messageClient' + str(index)).strip()] = "User " + str(index) \ + " message: " + userMessage if int(server['numberClients'][0:1]) != int(currentClients): currentClients = server['numberClients'][0:1] print int(currentClients) for x in [ i for i in range(int(currentClients)) if i != (index - 1) ]: server[('readClient' + str(x + 1)).strip()] = server[('messageClient'\ + str(index)).strip()] toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, "You: " + userMessage + "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def writeMessage(self, messageWrite): toplevel = chat.getUser() toplevel.messageBox.configure(state="normal") toplevel.messageBox.insert(Tk.END, messageWrite.strip() + "\n") toplevel.messageBox.insert(Tk.END, "\n") toplevel.messageBox.see(Tk.END) toplevel.messageBox.configure(state="disabled") def getInputUserName(self): return inputUserName def getClient(self): return client def getUser(self): return user.getClient()