-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
47 lines (45 loc) · 3.08 KB
/
Copy pathclient.py
File metadata and controls
47 lines (45 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import socket
import threading
# Choosing Nickname
print("""
▄████▄ ██░ ██ ▄▄▄ ██▀███ ▒█████ ███▄ █ ▄████▄ ██▓ ██▓ ▓█████ ███▄ █ ▄▄▄█████▓
▒██▀ ▀█ ▒▓██░ ██ ▒████▄ ▓██ ▒ ██▒▒██▒ ██▒ ██ ▀█ █ ▒██▀ ▀█ ▓██▒ ▒▓██▒ ▓█ ▀ ██ ▀█ █ ▓ ██▒ ▓▒
▒▓█ ▄░▒██▀▀██ ▒██ ▀█▄ ▓██ ░▄█ ▒▒██░ ██▒▓██ ▀█ ██▒ ▒▓█ ▄ ▒██░ ▒▒██▒ ▒███ ▓██ ▀█ ██▒▒ ▓██░ ▒░
▒▓▓▄ ▄██ ░▓█ ░██ ░██▄▄▄▄██▒██▀▀█▄ ▒██ ██░▓██▒ ▐▌██▒ ▒▒▓▓▄ ▄██ ▒██░ ░░██░ ▒▓█ ▄▓██▒ ▐▌██▒░ ▓██▓ ░
▒ ▓███▀ ░▓█▒░██▓▒▓█ ▓██░██▓ ▒██▒░ ████▓▒░▒██░ ▓██░ ░▒ ▓███▀ ▒░██████░░██░▒░▒████▒██░ ▓██░ ▒██▒ ░
░ ░▒ ▒ ▒ ░░▒░▒░▒▒ ▓▒█░ ▒▓ ░▒▓░░ ▒░▒░▒░ ░ ▒░ ▒ ▒ ░░ ░▒ ▒ ░░ ▒░▓ ░▓ ░░░ ▒░ ░ ▒░ ▒ ▒ ▒ ░░
░ ▒ ▒ ░▒░ ░░ ░ ▒▒ ░▒ ░ ▒ ░ ▒ ▒░ ░ ░░ ░ ▒░ ░ ▒ ░░ ░ ▒ ░ ▒ ░░ ░ ░ ░ ░░ ░ ▒░ ░
░ ░ ░░ ░ ░ ▒ ░░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
made by Perchant
""")
nickname = input("Choose your nickname: ")
# Connecting To Server
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('127.0.0.1', 55555))
# Listening to Server and Sending Nickname
def receive():
while True:
try:
# Receive Message From Server
# If 'NICK' Send Nickname
message = client.recv(1024).decode('ascii')
if message == 'NICK':
client.send(nickname.encode('ascii'))
else:
print(message)
except:
# Close Connection When Error
print("An error occured!")
client.close()
break
# Sending Messages To Server
def write():
while True:
message = '{}: {}'.format(nickname, input(''))
client.send(message.encode('ascii'))
# Starting Threads For Listening And Writing
receive_thread = threading.Thread(target=receive)
receive_thread.start()
write_thread = threading.Thread(target=write)
write_thread.start()