servp3.py 1.11 KB
Newer Older
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
print ("------------------------------------------servp3")

import time
import procbridge

print ('procbridge imported')

delegate = procbridge.Delegate()

@delegate.api
def echo(self, echo, **kw):
    print ("echo:", echo)
    # time.sleep(3)
    return ("Hello:" + echo)

@delegate.api
def shutdown(self, **kw):
    self.server.stop()

@delegate.api
def add(self, elements, conn, **kw):
    # return {'result': sum(x for x in elements)}  #long version
    for i in elements:
        self.server.write_back(conn, {'element':i})
    return sum(elements)

@delegate.api
def geterror(self, **kw):
    raise Exception("shit happened")

Philipp Auersperg's avatar
Philipp Auersperg committed
31 32
@delegate.api
def version(self, **kw):
Philipp Auersperg's avatar
Philipp Auersperg committed
33
    return '1.0.0 buildozer'
Philipp Auersperg's avatar
Philipp Auersperg committed
34

35 36 37 38 39 40 41 42
def runit():
    host = '0.0.0.0'
    port = 8077

    # start socket server
    server = procbridge.ProcBridgeServer(host, port, delegate)
    server.start()
    print('listening...')
Philipp Auersperg's avatar
Philipp Auersperg committed
43 44 45 46 47 48
    try:
        server.wait_for_stop()
    except Exception as e:
        print("shit happened:", str(e))
    except:
        print("some other shit happened")
49 50 51 52 53 54 55
    print('bye!')

print ('starting...')
try:
    runit()
except:
    print("shit happened")