Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added README.txt
Empty file.
52 changes: 52 additions & 0 deletions Test/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os
import socket
import threading
import time

os.system("cls")
print(" ...Welcome to the CryptoMessanger... ")

shutdown = False
join = False

def receving(name, sock):
while not shutdown:
try:
while True:
data, addr = sock.recvfrom(1024)
print(data.decode("utf-8"))
time.sleep(0.2)
except:
pass

host = socket.gethostbyname(socket.gethostname())
port = 0

server = ("192.168.0.103", 9090)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #socket difinition; protocol TCP/IP
sock.bind((host, port))
sock.setblocking(0)

alias = input("Name: ")

rT = threading.Thread(target = receving, args = ("RecvThread", sock))
rT.start()

while not shutdown:
if not join:
sock.sendto(("[" + alias + "] >> join chat ").encode("utf-8"), server)
join = True
else:
try:
message = input()
if message != "":
sock.sendto(("[" + alias + "] :: " + message).encode("utf-8"), server)
time.sleep(0.2)
except:
sock.sendto(("[" + alias + "] << left chat ").encode("utf-8"), server)
shutdown = True


rT.join()
sock.close()
1 change: 0 additions & 1 deletion Test/main.py

This file was deleted.

35 changes: 35 additions & 0 deletions Test/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import socket
import sys

os.system("cls")
host = socket.gethostbyname(socket.gethostname()) #ip of the server host machine
port = 9090

users = []

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #socket difinition; protocol TCP/IP
sock.bind((host, port))

quit = False
print(" ...Server started... ")

while not quit:
try:
data, addr = sock.recvfrom(1024)
if addr not in users: #add new user
users.append(addr)

print(data.decode("utf-8"))

#send the message for all users in chat except the sender
for user in users:
if addr != user:
sock.sendto(data, user)

except:
print(sys.exc_info())
print("[ Server stopped ]")
quit = True;

sock.close()