-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_one.py
More file actions
31 lines (25 loc) · 782 Bytes
/
client_one.py
File metadata and controls
31 lines (25 loc) · 782 Bytes
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
# -*- coding: utf-8 -*-
import socket
import sys
import Global_Params
HOST = Global_Params.M_HOST_TEST
PORT = Global_Params.M_PORT_TEST
def socket_client():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
except socket.error as msg:
print(msg)
sys.exit(1)
print(s.recv(1024)) # 目的在于接受:Accept new connection from (...
while 1:
data = input("please input work: ").encode()
s.send(data)
# return the length of string has sent
# s.sendall() try all data, call s.send() in recursion
print("from server to c-one: ", s.recv(1024))
if data.decode() == "exit":
break
s.close()
if __name__ == '__main__':
socket_client()