当前位置: 首页>>代码示例>>Python>>正文


Python Connection.join方法代码示例

本文整理汇总了Python中connection.Connection.join方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.join方法的具体用法?Python Connection.join怎么用?Python Connection.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connection.Connection的用法示例。


在下文中一共展示了Connection.join方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Client

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import join [as 别名]
class Client(threading.Thread):
    """
    The main class containing the wxPython graphical interface.
    """
    def __init__(self):
        print "client.py/Client.__init__"
        threading.Thread.__init__(self)
        self.isConnected = False
        self.connection = None
        self.tempCounter = 0
        self.tempName = random.randint(1, 100)

    def get_data(self):
        # TODO Return the eye position
        print "client.py/Client.get_data"
        data = utilities.get_data()
        if len(data):
            return data
        else:
            return None

    def connect(self):
        # Connect to server
        print "client.py/Client.connect"
        # Start another thread for the connection
        self.connection = Connection(netconstants.host, self.connected, self.display, self.lost_connection)
        self.connection.start()

    def disconnect(self):
        # Disconnect from server
        name = self.get_data()  # TODO whut
        self.connection.send_to_server(netconstants.CMD_QUIT + name)

    def send(self):
        # Send the data to server. Data is obtained by get_data().
        print "client.py/Client.send"
        if self.isConnected:
            data = self.get_data()
            print "client_send: ", data
            if data is not None:
                self.connection.send_to_server(data)

    def set_name(self):
        print "client.py/Client.set_name"
        # Set an alternative name
        if self.isConnected:
            name = self.get_data()  # TODO change this, name does not come from get_data()
            if len(name):
                self.connection.send_to_server(netconstants.CMD_RENAME + name)

    def connected(self):
        # This function is invoked in networking.Connection.run()
        print "client.py/Client.connected"
        self.isConnected = True

    def display(self, data):  # TODO DISPLAY EYE POSITION
        print "client.py/Client.display"
        # Display the eye positions
        utilities.display(data)

    def lost_connection(self, msg):  # TODO
        # This function is invoked in networking.Connection.run() when connection is lost
        print "client.py/Client.lostConnection"
        self.connection.join()

    def quit(self):
        # Quit connection
        print "client.py/Client.quit"
        if self.isConnected:
            self.isConnected = False
            self.connection.send_to_server(netconstants.CMD_QUIT + self.get_data())  # TODO ?
            self.connection.join()

    def run(self):
        # TODO
        import sys
        old_stdout = sys.stdout
        sys.stdout = open("clientout" + str(self.tempName) + ".txt", "w")
        # - TODO -

        self.connect()
        #time.sleep(0.2)
        while True:
            self.send()
            #time.sleep(0.05)

        #time.sleep(0.2)

        sys.stdout = old_stdout
开发者ID:Haaaaaank,项目名称:Dual-Eye-Tracking,代码行数:91,代码来源:client.py

示例2: Bot

# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import join [as 别名]
class Bot(object):
  def __init__(self, version = "HansBot"):
    self.version = version
    self.state = BotState(self)
    self.connection = None

  def start(self, server, nickname):
    if self.connection:
      LOGGER.warning("Starting the bot twice. Will disconnect old bot.")
      self.stop()
    self.connection = Connection(server, nickname, delegate = self.state,
                                 version = self.version)

  def join(self):
    self.connection.join()

  def send_message(self, user, message):
    self.connection.send_message(destination = user.session, message = message)

  def stop(self):
    self.connection.stop()
    self.connection = None

  def rejected(self):
    self.stop()

  def connected(self):
    pass

  def channels(self):
    return self.state.channels_by_id.values()

  def users(self):
    return self.state.users_by_session.values()

  def get_channel_by_id(self, id):
    return self.state.channels_by_id[id]

  def get_user_by_id(self, id):
    return self.state.users_by_id[id]

  def get_user_by_name(self, name):
    for u in self.state.users_by_session:
      if self.state.users_by_session[u].name == name:
        return self.state.users_by_session[u]
    return None

  def get_root(self):
    return self.state.root

  def is_connected(self):
    return self.connection is not None

  ##############################################################################
  ### EVENTS FROM STATE
  def on_text_message(self, from_user, to_users, to_channels, tree_ids,
                      message):
    if self.state.user.session in to_users:
      self.on_message_self(from_user = from_user, message = message)
    if to_users:
      self.on_message_users(from_user = from_user, to_users = to_users,
                            message = message)
    if to_channels:
      self.on_message_channels(from_user = from_user, to_channels = to_channels,
                               message = message)
    if tree_ids:
      self.on_message_trees(from_user = from_user, tree_ids = tree_ids,
                            message = message)

  def on_voice_ping(self, session_id):
    pass
  def on_voice_talk(self, from_user, sequence, data):
    pass

  ##############################################################################
  ### EVENTS
  def on_message_self(self, from_user, message):
    pass
  def on_message_users(self, from_user, to_users, message):
    pass
  def on_message_channels(self, from_user, to_channels, message):
    pass
  def on_message_trees(self, from_user, tree_ids, message):
    pass
开发者ID:Hicks85,项目名称:mumble-bots,代码行数:86,代码来源:bot.py


注:本文中的connection.Connection.join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。