0% found this document useful (0 votes)
19 views

Client 1. The Initialization For The Client. 2. Runtime of The Client

The document describes the initialization and functionality of a chat client application. 1. The client initializes the graphical user interface with buttons and text boxes for sending and receiving messages. 2. The client connects to a server socket on localhost when it runs. 3. Messages entered by the user are sent to the server socket when the send button is clicked.

Uploaded by

Ronnel M Prada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Client 1. The Initialization For The Client. 2. Runtime of The Client

The document describes the initialization and functionality of a chat client application. 1. The client initializes the graphical user interface with buttons and text boxes for sending and receiving messages. 2. The client connects to a server socket on localhost when it runs. 3. Messages entered by the user are sent to the server socket when the send button is clicked.

Uploaded by

Ronnel M Prada
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

CLIENT

1. The initialization for the client.


import threading
from socket import*
from Tkinter import*

root=Tk()
class ChatClient(Frame,threading.Thread):


def __init__(self):
threading.Thread.__init__(self)
Frame.__init__(self)
self.grid(row=2,column=3)


root.resizable(width=FALSE,height=FALS
E)
root.option_add("*font",("Calibri",12,"norm
al"))
root.title('CHATBOX')
self.quitbutton =

Button(self,text="Quit",fg='white',bg="red",
command=self.quits,font='Calibri -12 bold')
self.quitbutton.grid(row=1,column=3)

self.button=Button(self,text="Send",fg=
"blue",bg="gray",
command=self.mess,font='Calibri -12 bold')
self.button.grid(row=1,column=2)

self.lab=Label(self,text="Message",font='Ca
libri -12 bold')
self.lab.grid(row=1,column=0)

self.sendtext =
Entry(self,width=60,font='Calibri -12 bold')
self.sendtext.grid(row=1,column=1)

self.gettext =
Text(self,height=36,width=60,wrap=WORD
,bg="light blue",fg="black")
self.gettext.grid(row=0,columnspan=4)
self.pack()
self.start()


2. Runtime of the client
def run(self):
self.client =
socket(AF_INET,SOCK_STREAM)
self.client.connect(('localhost',3067))
self.recv()

3. Sending of messages from client to
server
def mess(self):
x=self.sendtext.get()
self.client.send(x)
self.sendtext.delete(0,END)

4. Disconnection of the client to the
server
def quits(self):
self.gettext.insert(END,"\n
Disconnected\n")
self.client.close()
#self.quit()

5. Receiving of messages from the
client to server
def recv(self):
while True:
reply = self.client.recv(1024)
self.gettext.insert(END,"\n"+reply)

if not reply:

self.gettext.insert(END,"\nConnection
Closed\n")
self.client.close()

if __name__=="__main__":
ChatClient().mainloop()

You might also like