forked from kevinsunsh/Diesel_for_APP_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
34 lines (30 loc) · 1.01 KB
/
server.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
# coding: utf8
import json
import diesel
import struct
from diesel.protocols.redis import RedisClient
from command import Command
from config import Configuration
config=Configuration()
config.get_configuration()
print config.config
def holla_back(addr):
while True:
#message = diesel.receive()
#print '%x\n' % message
#print '%r\n' % message
buffer = diesel.receive(4)
print "%r\n" % buffer
query_size, = struct.unpack('<i', buffer)
print "query size %r" % query_size
message = diesel.receive(query_size)
print "receive :%r" % message
command = Command(config.config['command'])
result = command.handle(message)
print "reply : %r" % result
result_size = len(result)
total_size = result_size
fmt = "<i%ds" % result_size
print result_size
diesel.send(struct.pack(fmt, total_size, result))
diesel.quickstart(diesel.Service(holla_back, port=config.config['server']['port'], track=True))