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


Python Socket.set_int_option方法代码示例

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


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

示例1: TestGeneralSocketMethods

# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import set_int_option [as 别名]
class TestGeneralSocketMethods(unittest.TestCase):
    def setUp(self):
        self.socket = Socket(PAIR)

    def tearDown(self):
        self.socket.close()

    def test_bind(self):
        endpoint = self.socket.bind(SOCKET_ADDRESS)

        self.assertNotEqual(None, endpoint)

    def test_connect(self):
        endpoint = self.socket.connect(SOCKET_ADDRESS)

        self.assertNotEqual(None, endpoint)

    def test_is_open_is_true_when_open(self):
        self.assertTrue(self.socket.is_open())

    def test_is_open_is_false_when_closed(self):
        self.socket.close()

        self.assertFalse(self.socket.is_open())

    def test_set_and_get_int_option(self):
        expected = 500

        self.socket.set_int_option(SOL_SOCKET, SNDBUF, expected)

        actual = self.socket.get_int_option(SOL_SOCKET, SNDBUF)
        self.assertEqual(expected, actual)
开发者ID:codypiersall,项目名称:nanomsg-python,代码行数:34,代码来源:test_general_socket_methods.py

示例2: sender

# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import set_int_option [as 别名]
def sender(queue, addresses, stype):
    """
    Bind a queue to a connecting nanomsg socket's multiple endpoints
    in a separate thread.
    
    Parameters
    ----------
    queue : Queue
        A Queue object to be emptied by sender socket
        
    addresses : list
        A list of strings of format '<protocol>://<ip>:<port>' to bind to
        
    stype : int
        One of the nanomsg scalability socket types: PUSH, PULL, PUB, SUB, PAIR
        
    Returns
    -------
        nanomsg socket object
    """
    with err.applicationbound():
      out_sock = Socket(stype)
      
      out_sock.set_int_option(SOL_SOCKET, SNDTIMEO, 1000)
      
      for address in addresses:
          endpoint = out_sock.connect(address)
          out_endpoints.append(endpoint)
        
      def send_messages():
          """ """
          while True:
              try:
                  out_sock.send(queue.get(block=True))
                  log.info("Message has been sent")
              except NanoMsgAPIError as e:
                  log.debug(e)
                  log.debug(dir(e))
                  

      receiver = threading.Thread(target=send_messages)
      receiver.start()

      return out_sock
开发者ID:Zogg,项目名称:Tiltai,代码行数:46,代码来源:nanolink.py

示例3: ServiceDiscovery

# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import set_int_option [as 别名]
class ServiceDiscovery(object):
 
    def __init__(self, port, deadline=5000):
        self.socket = Socket(SURVEYOR)
        self.port = port
        self.deadline = deadline
        self.services = defaultdict(set)
 
    def bind(self):
        self.socket.bind('tcp://172.30.42.174:%s' % self.port)
        self.socket.set_int_option(SURVEYOR, SURVEYOR_DEADLINE, self.deadline)
 
    def discover(self):
        if not self.socket.is_open():
            return self.services
 
        self.services = defaultdict(set)
        self.socket.send('service query')
 
        while True:
            try:
                response = self.socket.recv()
            except NanoMsgAPIError:
                break
 
            service, address = response.split('|')
            self.services[service].add(address)
 
        return self.services
 
    def resolve(self, service):
        providers = self.services[service]
 
        if not providers:
            return None
 
        return random.choice(tuple(providers))
 
    def close(self):
        self.socket.close()
开发者ID:marchon,项目名称:upush,代码行数:42,代码来源:NanoServiceDiscovery.py

示例4: sender

# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import set_int_option [as 别名]
def sender(queue, network, stype=PUSH):
    out_sock = Socket(stype)
    
    out_sock.set_int_option(SOL_SOCKET, SNDTIMEO, 1000)
    
    for node in network['nodes']:
        endpoint = out_sock.connect('tcp://{ip}:{port}'.format(ip=node['ip'], 
                                                               port=node['port']))
        out_endpoints.append(endpoint)
      
    def send_messages():
        while True:
            try:
                out_sock.send(queue.get(block=True))
                print("Message has been sent")
            except NanoMsgAPIError as e:
                print(e)
                print(dir(e))
                

    receiver = threading.Thread(target=send_messages)
    receiver.start()

    return out_sock
开发者ID:Zogg,项目名称:Tiltai,代码行数:26,代码来源:control.py


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