-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rpcclient.py
47 lines (41 loc) · 1.18 KB
/
Rpcclient.py
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 time, socket, sys
import re
print("\nWelcome to Chat Room\n")
print("Initialising....\n")
time.sleep(1)
s = socket.socket()
shost = socket.gethostname()
ip = socket.gethostbyname(shost)
print(shost, "(", ip, ")\n")
host = input(str("Enter server address: "))
name = input(str("\nEnter your name: "))
port = 1234
print("\nTrying to connect to ", host, "(", port, ")\n")
time.sleep(1)
s.connect((host, port))
print("Connected...\n")
s.send(name.encode())
s_name = s.recv(1024)
s_name = s_name.decode()
print(s_name, "has joined the chat room\nEnter [e] to exit chat room\n")
while True:
message = s.recv(1024)
message = message.decode()
print(s_name, ":", message)
message = input(str("Me : "))
if message == "[e]":
message = "Left chat room!"
s.send(message.encode())
print("\n")
break
elif re.search("^sending-file",message):
buffer = message.split(':')
filename = buffer[1]
print(filename)
rqst_data = "ready"
s.send(rqst_data.encode())
file_data = s.recv(1024)
file_data = file_data.decode()
file = open(filename, "w")
file.write(file_data)
s.send(message.encode())