-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreceive_utf8.py
52 lines (43 loc) · 1.25 KB
/
receive_utf8.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
#coding:utf-8
import datetime
import sys
import time
import socket
import threading
HOST = '---'
PORT = ---
CLIENTNUM = 3
class ConnClient(threading.Thread):
def __init__(self, conn, addr):
threading.Thread.__init__(self)
self.stop_event = threading.Event()
self.conn_socket = conn
self.addr = addr
def run(self):
try:
while (1):
# senddata = raw_input(str(self.addr)+"SendData:")
# self.conn_socket.send(senddata)
recvdata = self.conn_socket.recv(1024)
print "ReciveData"+recvdata+str(self.addr)
if (recvdata == "quit"):
break
except socket.error:
print "connect errer"
finally:
self.conn_socket.close()
print "connect close"
def stop(self):
self.conn_socket.cloce()
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind((HOST, PORT))
sock.listen(CLIENTNUM)
while (1):
conn, addr = sock.accept()
print("Connected by"+str(addr))
connClientThread = ConnClient(conn, addr)
connClientThread.setDaemon(True)
connClientThread.start()
if __name__ == '__main__':
main()