Instant Messaging
Instant Messaging
EECS563
DECEMBER 7, 2023
MAX DJAFAROV
Instant Messaging Platform
import socket
import threading
import sqlite3
while True:
data = client_socket.recv(1024).decode().strip()
if not data:
break
if command == "register":
if len(message) == 2:
username, password = message
if check_credentials(username, password):
client_socket.send("Username already exists!\n".encode())
else:
add_user(username, password)
client_socket.send("Registration successful!\n".encode())
else:
client_socket.send("Invalid command format!\n".encode())
else:
client_socket.send(f"{recipient} is not
online!\n".encode())
else:
client_socket.send("Invalid command format!\n".encode())
import socket
while True:
option = input("Enter 'login' to log in or 'signup' to register: ")
if option.lower() == 'login':
# Get user inputs for login
username_login = input("Enter username to login: ")
password_login = input("Enter password to login: ")
if option.lower().startswith("list"):
online_users = client_socket.recv(1024).decode()
print(online_users)
elif option.lower().startswith("send"):
client_socket.send(option.encode())
send_status = client_socket.recv(1024).decode()
print(send_status)
else:
print("Invalid option entered!")
continue
break
else:
print("Invalid option entered! Please enter 'login' or 'signup'.")
continue
SAMPLE OUTPUT
First of all, the server file is run and it successfully starts listening for connections.
After that, the client file is run. It shows the welcome message and ask for login and signup. If
the user is already registered, then one should go for ‘login’ option. Otherwise, go for ‘signup’.
If user is already registered, it will show that the user already exists.
After successful login, it will ask whether you want to see online users list or send message to
anyone.
If the option ‘list’ is selected, then it will show the list of online users.
Now, a message a sent to the user ‘david’ using this command ‘send david Hello! How are
This process can continue and many more users can be added using different terminals.
THE END