Skip to content

Commit 0dd9fb7

Browse files
committed
Reformated scripts and updated indentation
1 parent 07e0697 commit 0dd9fb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1287
-767
lines changed

Chat Room 101/src/Client.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from threading import Thread
55
from time import sleep
66

7+
78
def enter(self):
89
global message_sent
910
message = my_message.get()
@@ -15,20 +16,23 @@ def enter(self):
1516
s.close()
1617
window.quit()
1718

19+
1820
message_sent = False
1921

22+
2023
def receive():
21-
while (True):
24+
while True:
2225
try:
2326
global message_sent
2427
message = s.recv(1024).decode("utf8")
25-
message_list.insert(tkinter.END,message)
26-
if (message_sent != True):
28+
message_list.insert(tkinter.END, message)
29+
if message_sent != True:
2730
print("\a")
2831
message_sent = False
2932
except:
3033
break
3134

35+
3236
def send():
3337
global message_sent
3438
message = my_message.get()
@@ -40,58 +44,67 @@ def send():
4044
s.close()
4145
window.quit()
4246

47+
4348
def closing():
4449
my_message.set("#quit")
4550
send()
4651

47-
while(True):
52+
53+
while True:
4854
try:
4955
host = input("Enter Host IP : ")
5056
port = int(input("Enter Port : "))
5157
break
5258
except:
5359
print("Please verify details entered")
54-
60+
5561
window = Tk()
56-
data = open("../assets/version.txt" , "r").read()
62+
data = open("../assets/version.txt", "r").read()
5763
window.title("Chat Room 101 | " + data)
5864
window.iconbitmap("../assets/Icon.ico")
5965
window.configure(bg="white")
6066

61-
message_frame = Frame(window,height=100,width=100,bg="black")
67+
message_frame = Frame(window, height=100, width=100, bg="black")
6268

6369
my_message = StringVar()
6470
my_message.set("")
6571

6672
scroll_bar = Scrollbar(message_frame)
6773

68-
message_list = Listbox(message_frame,height = 15,width = 100,bg = "black", fg = "white", yscrollcommand=scroll_bar.set)
69-
70-
scroll_bar.pack(side=RIGHT,fill=Y)
71-
message_list.pack(side=LEFT,fill=BOTH)
74+
message_list = Listbox(
75+
message_frame,
76+
height=15,
77+
width=100,
78+
bg="black",
79+
fg="white",
80+
yscrollcommand=scroll_bar.set,
81+
)
82+
83+
scroll_bar.pack(side=RIGHT, fill=Y)
84+
message_list.pack(side=LEFT, fill=BOTH)
7285
message_frame.pack()
7386

74-
button_label = Label(window,text = "Enter Your Message",bg="white")
87+
button_label = Label(window, text="Enter Your Message", bg="white")
7588
button_label.pack()
7689

77-
text_field = Entry(window,textvariable=my_message, bg="white",width = 50)
90+
text_field = Entry(window, textvariable=my_message, bg="white", width=50)
7891
text_field.pack()
7992

80-
send_button = Button(window,text = "Send", bg="white", command = send)
93+
send_button = Button(window, text="Send", bg="white", command=send)
8194
send_button.pack()
82-
window.bind('<Return>',enter)
95+
window.bind("<Return>", enter)
8396

84-
window.protocol("WM_DELETE_WINDOW",closing)
97+
window.protocol("WM_DELETE_WINDOW", closing)
8598

8699
s = socket.socket()
87100

88101
try:
89-
s.connect((host,port))
102+
s.connect((host, port))
90103
except:
91104
print("Please Verify Host IP and Port Number")
92105
sleep(5)
93106
sys.exit(0)
94107

95108
recieve_thread = Thread(target=receive)
96109
recieve_thread.start()
97-
mainloop()
110+
mainloop()

Chat Room 101/src/Server.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from threading import Thread
33
import time
44

5-
data = open("../assets/version.txt" , "r").read()
5+
data = open("../assets/version.txt", "r").read()
66
print("Chat Room 101 | " + data)
77
time.sleep(1)
88
clients = {}
@@ -13,39 +13,46 @@
1313
port = 8080
1414

1515
s = socket.socket()
16-
s.bind((host,port))
16+
s.bind((host, port))
1717
print(host, ip)
18-
print("Ask clients to enter host IP as :",ip,"and port as :",port)
18+
print("Ask clients to enter host IP as :", ip, "and port as :", port)
19+
1920

2021
def accept_client():
21-
while (True):
22-
client_con,client_address=s.accept()
23-
client_con.send("Hey! Welcome to the Chat Room. Enter Your Name To Continue.".encode("utf8"))
22+
while True:
23+
client_con, client_address = s.accept()
24+
client_con.send(
25+
"Hey! Welcome to the Chat Room. Enter Your Name To Continue.".encode("utf8")
26+
)
2427
addresses[client_address] = client_address
25-
t2 = Thread(target=handle_client,args=(client_con,client_address)).start()
28+
t2 = Thread(target=handle_client, args=(client_con, client_address)).start()
2629
print(client_address, "Has Connected")
27-
30+
2831

2932
def broadcast(message, prefix=""):
3033
for x in clients:
31-
x.send(bytes(prefix, "utf8") +message)
34+
x.send(bytes(prefix, "utf8") + message)
3235

3336

34-
def handle_client(con,adr):
37+
def handle_client(con, adr):
3538
name = con.recv(1024).decode("utf8")
36-
welcome_message = "Thanks for using this Chat Room " + name + ". You can use #quit if you want to exit"
39+
welcome_message = (
40+
"Thanks for using this Chat Room "
41+
+ name
42+
+ ". You can use #quit if you want to exit"
43+
)
3744
con.send(bytes(welcome_message, "utf8"))
38-
print(name,"has joint the chat")
45+
print(name, "has joint the chat")
3946

4047
message = name + " has joint the chat!"
4148
broadcast(bytes(message, "utf8"))
4249

4350
clients[con] = name
4451

4552
try:
46-
while(True):
53+
while True:
4754
message = con.recv(1024)
48-
if(message != bytes("#quit", "utf8")):
55+
if message != bytes("#quit", "utf8"):
4956
broadcast(message, name + ": ")
5057
else:
5158
con.close()
@@ -54,9 +61,10 @@ def handle_client(con,adr):
5461
except:
5562
print(name + " has left the chat")
5663

64+
5765
if __name__ == "__main__":
5866
s.listen()
5967
print("The Server Is Now Online")
6068
t1 = Thread(target=accept_client)
6169
t1.start()
62-
t1.join() # Waits for one thread to stop before running the next.
70+
t1.join() # Waits for one thread to stop before running the next.

0 commit comments

Comments
 (0)