-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMiniWeb.py
66 lines (56 loc) · 1.67 KB
/
MiniWeb.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
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: bsj
#
# Created: 14-12-2013
# Copyright: (c) bsj 2013
# Licence: <your licence>
#-------------------------------------------------------------------------------
import unittest
import socket
import threading
import time
class MiniWeb(threading.Thread):
def __init__(self, port):
threading.Thread.__init__(self)
self.port = port
self.s = None
def run(self):
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.s.bind(("localhost", self.port))
self.s.listen(1)
while 1:
print ('이해를 할 수 없군')
try:
conn, addr = self.s.accept()
print('한글이 왜 깨지지' , addr)
recvmsg = conn.recv(1024)
conn.send('sdfasd'.encode('utf-8'))
conn.close()
except socket.error:
break
def simpleResponse(self, msg):
return """HTTP/1.1 200 OK
Server: SimpleHttpServer
Content-type: text/plain
Content-Length: %s
%s""" % (len(msg), msg)
def stop(self):
if self.s:
self.s.close()
self.join()
class TestMiniWeb(unittest.TestCase):
def test1(self):
miniweb = MiniWeb(port=8080)
miniweb.start()
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("localhost", 8080))
#s.send("abc")
s.close()
time.sleep(0.5)
miniweb.stop()
if __name__ == "__main__":
#unittest.main()
MiniWeb(port=8081).start()