Question: import socket SERVER _ HOST = ' 1 2 7 . 0 . 0 . 1 ' SERVER _ PORT = 5 3 7 8

import socket
SERVER_HOST ='127.0.0.1'
SERVER_PORT =5378
FORBIDDEN_SYMBOLS ="!@#$%^&*"
def read_usernames():
usernames = set()
try:
with open("usernames.txt","r") as file:
for line in file:
usernames.add(line.strip())
except FileNotFoundError:
pass # Dosya bulunamazsa bo bir kme dndr
return usernames
def write_username(username):
with open("usernames.txt","a") as file:
file.write(username +"
")
print('Welcome to Chat Client. Enter your login:')
username = input()
existing_usernames = read_usernames()
forbidden = False
for symbol in FORBIDDEN_SYMBOLS:
if symbol in username:
forbidden = True
break
if forbidden:
print(f"Cannot log in as {username}. That username contains disallowed characters.")
elif username in existing_usernames:
print(f"Cannot log in as {username}. That username is already in use.")
else:
existing_usernames.add(username)
write_username(username)
try:
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host_port =(SERVER_HOST, SERVER_PORT)
client_socket.connect(host_port)
print(f"Successfully logged in as {username}!")
data = client_socket.recv(4096)
if not data:
print("Socket is closed.")
else:
print(f"Read data from socket: {data.decode()}")
client_socket.close()
except OSError as msg:
print(msg)
I am getting errors which are shown in the below. Can you help me to fix them?
[ x ] chat_005. Expect client to not restart after a failed log in attempt Failed! The list of tags is RI1 RT7 RA6
Your client did not start or connected to a wrong server port
[ x ] chat_006. Log in with busy server, expect failure, and shut client down gracefully Failed! The list of tags is RI1 RT7 RI6
Error message is unexpected output at step logging into busy server!
Expected output:
Cannot log in. The server is full!
Actual output (the last printed line):
Successfully logged in as aRsnlrRvAMMwv!
Total program output:
Welcome to Chat Client. Enter your login:
aRsnlrRvAMMwv
Successfully logged in as aRsnlrRvAMMwv!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!