-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
87 lines (65 loc) · 2.08 KB
/
app.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
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
from simple_websocket_server import WebSocketServer, WebSocket
import http.server as SimpleHTTPServer
import socketserver as SocketServer
import logging
import time
import sys
import os
from threading import Thread
from concurrent import futures
import grpc
import srv_pb2
import srv_pb2_grpc
PORT = 8000
WS_PORT = 8001
GRPC_PORT = 8082
class GetHandler(
SimpleHTTPServer.SimpleHTTPRequestHandler
):
def do_GET(self):
logging.error(self.headers)
logging.error(os.system("uname -a"))
SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
def do_POST(self):
logging.error(self.headers)
def do_PUT(self):
logging.error(self.headers)
i=0
while i <= 10:
i * 50
def do_HEAD(self):
logging.error("exiting")
sys.exit(1)
class SimpleEcho(WebSocket):
def handle(self):
# echo message back to client
self.send_message(self.data)
def connected(self):
print(self.address, 'connected')
def handle_close(self):
print(self.address, 'closed')
class Greeter(srv_pb2_grpc.GreeterServicer):
def greet(self, request, context):
print("Got request " + str(request))
return srv_pb2.ServerOutput(message='{0} {1}!'.format(request.greeting, request.name))
def stream(self, request, context):
while True:
if request.greeting != "sleep":
yield srv_pb2.ServerOutput(message='xxxxx')
time.sleep(1)
def grpc_server():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=2))
srv_pb2_grpc.add_GreeterServicer_to_server(Greeter(), server)
server.add_insecure_port('[::]:8082')
print("gRPC starting on 8082")
server.start()
server.wait_for_termination()
Handler = GetHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
server = WebSocketServer('0.0.0.0', WS_PORT, SimpleEcho)
print("Serving HTTP on port :8000")
print("Serving Websocket on port :8001")
Thread(target=server.serve_forever).start()
Thread(target=grpc_server).start()
httpd.serve_forever()