-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
52 lines (40 loc) · 1.36 KB
/
client.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
48
49
50
51
52
import socket
import select
import sys
from message import Message
import pickle
host = '127.0.0.1'
port = 12345
mySocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mySocket.connect((host, port))
_name = str(sys.argv[1])
m = Message(_name, "")
while True:
sockets_list = [sys.stdin, mySocket]
read_sockets, write_socket, error_socket = select.select(sockets_list, [], [])
"""
There are two possible input situations. Either the
# user wants to give manual input to send to other people,
# or the server is sending a message to be printed on the
# screen. Select returns from sockets_list, the stream that
# is reader for input. So for example, if the server wants
# to send a message, then the if condition will hold true
# below.If the user wants to send a message, the else
# condition will evaluate as true
"""
for socks in read_sockets:
if socks == mySocket:
data = socks.recv(2048)
tm = pickle.loads(data)
print(str(tm._name)+": " + str(tm._message))
else:
"""
< _io.TextIOWrapper
name = '<stdin>'
mode = 'r'
encoding = 'UTF-8' >
"""
message = input()
m.updateMessage(message)
mySocket.send(pickle.dumps(m))
mySocket.close()