-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCODE CLIENT
More file actions
37 lines (30 loc) · 1.09 KB
/
CODE CLIENT
File metadata and controls
37 lines (30 loc) · 1.09 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
import socket
import threading
import cesarmodule
nickname = input("Choose your nickname : ").strip()
while not nickname:
nickname = input("Your nickname should not be empty : ").strip()
my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = "192.168.56.1" # "127.0.1.1"
port = 4444
code = 1
my_socket.connect((host, port))
def thread_sending():
while True:
message_to_send = str(input(''))
code = int(input('Enter 2 to encode your message') or 1 )
if message_to_send:
if code == 2:
message_to_send = cesarmodule.myencode(message_to_send)
message_with_nickname = nickname + " : " + message_to_send
else:
message_with_nickname = nickname + " : " + message_to_send
my_socket.send(message_with_nickname.encode())
def thread_receiving():
while True:
message = my_socket.recv(1024).decode()
print(message)
thread_send = threading.Thread(target=thread_sending)
thread_receive = threading.Thread(target=thread_receiving)
thread_send.start()
thread_receive.start()