-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.py
74 lines (38 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
import socket
import sys
import json
from multiprocessing import Process
class LoginServer:
def __init__(self, host_ip, port):
self.HOST_IP = host_ip
self.PORT= port
self.TIMEOUT = 200
def send_recv(self):
client_socks = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socks.settimeout(self.TIMEOUT)
client_socks.connect((self.HOST_IP, self.PORT))
HELLO = 'HELLO'
client_socks.sendall(HELLO)
while True:
data_json = client_socks.recv(4096)
# date_json like ['Show', really_data]
data = json.loads(data_json)
print data[1]
if len(data[0]):
answer = raw_input('[%s]>>:' % data[0])
send_process = Process(target = sendp, args = (client_socks, answer))
send_process.daemon = True
send_process.start()
else:
answer = raw_input('[Normal Mod]>>:')
send_process = Process(target = sendp, args = (client_socks, answer))
send_process.daemon = True
send_process.start()
def sendp(client_socks, answer):
client_socks.sendall(answer)
def main():
init = LoginServer('127.0.0.1', 8001)
init.send_recv()
if __name__ == "__main__":
main()