???????????????
?????lose ???????[ 2016/12/30 11:20:26 ] ??????????????? ???????
???????
????· ????????????????????????
????· ????????κ??????????????????????????????????????????????
????????·
????· ???????webserver??????????????
????· ?????????ж??????????????????????????????????????????ó?????apache??
????????
???????????
__author__ = "shikun"
class Const(object):
log = "D:/app/Apache2.2/htdocs/client.log" # apache ??log·??
APAHEC_IP = "192.168.1.38" # ????ip
PORT_NUMBER = 8088 # ????
????web server.py
from http.server import BaseHTTPRequestHandler??HTTPServer
import urllib.parse
from common import operateFile
from common.customConst import Const
class myHandler(BaseHTTPRequestHandler):
# Handler for the GET requests
def do_GET(self):
print('Get request received')
req = urllib.parse.unquote(self.path)
result = urllib.parse.parse_qs(req[2:]) # ??????????
self.send_response(200)
self.send_header('Content-type'??'text/html')
self.end_headers()
# Send the html message
self.wfile.write(b"ok!") #??????????????
operateFile.write_txt(line=result["msg"][0]?? f_path=Const.log) # ????????????????????
try:
server = HTTPServer((Const.APAHEC_IP?? Const.PORT_NUMBER)?? myHandler)
print ('Started httpserver on port ' ?? Const.PORT_NUMBER)
server.serve_forever()
except KeyboardInterrupt:
print ('^C received?? shutting down the web server')
server.socket.close()
????client.py
from multiprocessing import Process
from gevent import monkey; monkey.patch_all()
import gevent
import requests
import json
from common.customConst import Const
url = "http://rap.taobao.org/mockjsdata/10296/getUserInfo?id=2"
num = 10
result = {"success": 0?? "computer": "???????1"?? "cpu": 4?? "men": 4?? sum: 10} # ????????
class Producer(object):
'''
Э???????
'''
def __init__(self):
self._rungevent()
self.h = 0
def _rungevent(self):
jobs = []
for i in range(num): #windows???ж??????
jobs.append(gevent.spawn(self.produce))
gevent.joinall(jobs)
requests.get("http://"+Const.APAHEC_IP+":"+ str(Const.PORT_NUMBER)+"/?msg="+str(result)) # ????????????????
def produce(self):
r = requests.get(url)
if r.status_code == 200:
r.encoding = 'UTF-8'
if json.loads(r.text)["code"] == 0:
result["success"] += 1
else:
print("????")
def main():
p = Process(target=Producer?? args=()) # ??????????Э??
p.start()
# p1 = Process(target = Producer?? args=())
# p1.start()
if __name__ == '__main__':
main()
???????????????????????????????磬?????+????????
???????
??????????
???????????????????????????????д???????????
?????????????????????????.????????????ɡ???????????????????·
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11