2017-10-17 21:32:11 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2017-10-18 06:53:15 -07:00
|
|
|
import mod_python, json, socket, base64
|
2017-10-17 21:32:11 -07:00
|
|
|
|
|
|
|
try:
|
|
|
|
from mod_python import apache
|
|
|
|
apacheAvailable = True
|
|
|
|
except ImportError:
|
|
|
|
apacheAvailable = False
|
|
|
|
print('failed')
|
|
|
|
|
|
|
|
def post(req, params):
|
2017-10-18 06:53:15 -07:00
|
|
|
err = 'none'
|
|
|
|
dataLen = 0
|
2017-10-17 21:32:11 -07:00
|
|
|
jobj = json.loads(params)
|
2017-10-18 06:53:15 -07:00
|
|
|
data = base64.b64decode(jobj['data'])
|
|
|
|
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
|
|
sock.settimeout(3) # seconds
|
|
|
|
addr = ("127.0.0.1", 10997)
|
|
|
|
sock.sendto(data, addr)
|
|
|
|
|
2017-10-18 07:09:05 -07:00
|
|
|
responses = []
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
data, server = sock.recvfrom(1024)
|
|
|
|
responses.append(base64.b64encode(data))
|
|
|
|
except socket.timeout:
|
|
|
|
#If data is not received back from server, print it has timed out
|
|
|
|
err = 'timeout'
|
|
|
|
break
|
2017-10-18 06:53:15 -07:00
|
|
|
|
2017-10-18 07:09:05 -07:00
|
|
|
jobj = {'err' : err, 'data' : responses}
|
2017-10-17 21:32:11 -07:00
|
|
|
return json.dumps(jobj)
|
|
|
|
|
|
|
|
def main():
|
2017-10-18 06:53:15 -07:00
|
|
|
params = { 'data' : 'V2VkIE9jdCAxOCAwNjowNDo0OCBQRFQgMjAxNwo=' }
|
|
|
|
params = json.dumps(params)
|
|
|
|
print(post(None, params))
|
2017-10-17 21:32:11 -07:00
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|