def start_anymesh(name, listens_to):
    global delegate, any_mesh
    delegate = AmDelegate()
    if 'any_mesh' not in globals():
        any_mesh = AnyMesh(name, listens_to, delegate)
Ejemplo n.º 2
0
    def connected_to(self, device_info):
        print('left connected to ' + device_info.name)

    def disconnected_from(self, name):
        pass

    def received_msg(self, message):
        print('left received message from ' + message.sender)
        print('message: ' + message.data['msg'])
        leftMesh.request('right', {'msg': 'back at ya righty!'})


class RightDelegate(AnyMeshDelegateProtocol):
    def connected_to(self, device_info):
        print('right connected to ' + device_info.name)
        rightMesh.request('left', {'msg': 'hey lefty!'})

    def disconnected_from(self, name):
        pass

    def received_msg(self, message):
        print('right received message from ' + message.sender)
        print('message: ' + message.data['msg'])


leftMesh =AnyMesh('left', 'global', LeftDelegate())

rightMesh = AnyMesh('right', 'global', RightDelegate())

AnyMesh.run()
Ejemplo n.º 3
0
    def connected_to(self, device_info):
        print('left connected to ' + device_info.name)

    def disconnected_from(self, name):
        pass

    def received_msg(self, message):
        print('left received message from ' + message.sender)
        print('message: ' + message.data['msg'])
        leftMesh.request('right', {'msg': 'back at ya righty!'})


class RightDelegate(AnyMeshDelegateProtocol):
    def connected_to(self, device_info):
        print('right connected to ' + device_info.name)
        rightMesh.request('left', {'msg': 'hey lefty!'})

    def disconnected_from(self, name):
        pass

    def received_msg(self, message):
        print('right received message from ' + message.sender)
        print('message: ' + message.data['msg'])


leftMesh = AnyMesh('left', 'global', LeftDelegate())

rightMesh = AnyMesh('right', 'global', RightDelegate())

AnyMesh.run()
Ejemplo n.º 4
0
 def test_connect(self):
     self.sender = AnyMesh('sender', ['stuff', 'things'], self)
     self.receiver = AnyMesh('receiver', ['stuff', 'things'], self)
     AnyMesh.run()
Ejemplo n.º 5
0
from anymesh import AnyMesh, AnyMeshDelegateProtocol, MeshMessage, MeshDeviceInfo
import json
import subprocess


class AmDelegate(AnyMeshDelegateProtocol):
    def connected_to(self, anymesh, device_info):
        pass

    def disconnected_from(self, anymesh, name):
        pass

    def received_msg(self, anymesh, message):
        msg = message.data
        if msg[0] == 'cmd':
            any_mesh.request(message.sender,
                             'stdout ' + subprocess.check_output(msg[1:]))

        elif msg[0] == 'msg':
            print msg[1:]


any_mesh = AnyMesh(raw_input('node name: '), [], AmDelegate())
any_mesh.run()
Ejemplo n.º 6
0
from anymesh import AnyMesh, AnyMeshDelegateProtocol, MeshMessage, MeshDeviceInfo
from crochet import setup
import json
setup()


class AmDelegate(AnyMeshDelegateProtocol):
    def connected_to(self, anymesh, device_info):
        pass

    def disconnected_from(self, anymesh, name):
        pass

    def received_msg(self, anymesh, message):
        msg = message.data
        if msg[0] == 'stdout':
            print ' '.join(msg[1:])
        elif msg[0] == 'msg':
            print msg[1:]
        else:
            print 'unhandled: %s' % msg


any_mesh = AnyMesh(raw_input('server name: '), [], AmDelegate())

while True:
    r = raw_input('> ').split()
    print r[1:]
    any_mesh.request(r[0], r[1:])
Ejemplo n.º 7
0
 def test_connect(self):
     self.sender = AnyMesh('sender', ['stuff', 'things'], self)
     self.receiver = AnyMesh('receiver', ['stuff', 'things'], self)
     AnyMesh.run()
Ejemplo n.º 8
0
 def test_connect(self):
     self.leftMesh = AnyMesh('left', ['stuff', 'things'], self)
     self.rightMesh = AnyMesh('right', ['stuff', 'things'], self)
     AnyMesh.run()