예제 #1
0
 def send(self, service_name, method, *args):
     socket = NetRPC()
     socket.connect(self.hostname, self.port)
     socket.mysend((service_name, method, )+args)
     result = socket.myreceive()
     socket.disconnect()
     return result
 def disconnect(self, socket):
     try:
         socket.disconnect()
         return True
     except BaseException as e:
         print(f"Error trying to disconnect due to '{e}'")
         return False
예제 #3
0
파일: wolf.py 프로젝트: burunduk3/testsys
 def cb_data( data ):
     if len(data) == 0:
         log("INFO: abnormal disconnecting peer %s" % str(peer))
         socket.disconnect()
         return
     nonlocal tail
     data = data.split(b'\n')
     tail += data[0]
     for x in data[1:]:
         yield (handle_packet, (tail,))
         tail = x
예제 #4
0
파일: wolf.py 프로젝트: burunduk3/testsys
 def cb_data( data ):
     nonlocal tail
     if len(data) == 0:
         log.info("abnormal disconnecting unix peer #%d" % id)
         socket.disconnect()
         return []
     # log.debug("received from unix#%d: %s" % (id, repr(data)))
     data = data.split(b'\n')
     tail += data[0]
     for x in data[1:]:
         handle_command(tail.decode('utf8').split())
         tail = x
     return []
예제 #5
0
    def _on_cmd_logout(self,
                       e: Event,
                       entity: str = '',
                       args: List[str] = []) -> None:

        if not args:
            socket.disconnect()

        else:
            text = f'目前不支援參數請勿輸入任何數值'

            role = Role.instance(entity)
            Channel.toRole(entity, Message.TEXT, text)
예제 #6
0
파일: rpc.py 프로젝트: Unifield/ufcheck
class NetRPCConnector(Connector):
    PROTOCOL = 'netrpc'

    def __init__(self,
                 hostname,
                 port=8070,
                 is_gzip=False,
                 timeout=10.0,
                 retry=10):
        Connector.__init__(self, hostname, port, timeout=timeout)
        self._logger = logging.getLogger('connector.netrpc')
        self.is_gzip = is_gzip
        self.retry = retry

    def send(self, service_name, method, *args):
        i = 0
        retry = True
        result = False
        error = False
        while retry:
            try:
                retry = False
                #US-309: Reset value of error in the previous rounds, otherwise the system will raise exception regardless of the result of the next try!
                error = False
                socket = NetRPC(is_gzip=self.is_gzip, timeout=self.timeout)
                socket.connect(self.hostname, self.port)
                socket.mysend((
                    service_name,
                    method,
                ) + args)
                result = socket.myreceive()
            except Exception, e:
                error = e
                print "Error when connecting to %(hostname)s:%(port)d" % dict(
                    hostname=self.hostname, port=self.port)
                if i < self.retry:
                    retry = True
                i += 1

        socket.disconnect()
        if error:
            raise RuntimeError(
                "Unable to proceed for the following reason: %s" %
                (e.faultCode if hasattr(e, 'faultCode') else tools.ustr(e)))
        return result
def end(string=None):
	socket.send(message)
	socket.disconnect()
	sql.close_connection()
	sys.exit(string)
예제 #8
0
 def getMessage(self):
     while self.server.isActive():
         r_data = self.server.recv()
         if len(r_data) > 0:
             socket.disconnect()
             return r_data[0]
예제 #9
0
파일: wolf.py 프로젝트: burunduk3/testsys
 def cb_halt():
     log("INFO: judge peer %s disconnected" % str(peer))
     # todo: shutdown judge and restart its active actions
     socket.disconnect()
     return []
예제 #10
0
파일: wolf.py 프로젝트: burunduk3/testsys
 def cb_halt():
     log("INFO: peer %s disconnected" % str(peer))
     socket.disconnect()
     return []
예제 #11
0
파일: wolf.py 프로젝트: burunduk3/testsys
 def cb_halt():
     log.info("disconnect unix #%d" % id)
     socket.disconnect()
     return []
예제 #12
0
def disconnect():
    socket.disconnect(0)
예제 #13
0
    func_name = msg[0]
    args = msg[1:]
    ret = getattr(server, func_name)(*args)
    return ret


while True:
    msg = msgpack.unpackb(socket.recv(), raw=False)
    ret = None

    if msg[0] == 'exit':
        socket.send_pyobj('ok')
        break

    elif msg[0] == 'cmd_list':
        for m in msg[1:]:
            ret = exec_cmd(m)
    else:
        ret = exec_cmd(msg)

    socket.send(msgpack.packb(ret, use_bin_type=True))

if FLAGS.bind:
    socket.unbind(FLAGS.addr)
else:
    socket.disconnect(FLAGS.addr)

socket.close()
context.term()
print('gibson simulation server terminated')