本文整理汇总了Python中nanomsg.Socket.is_open方法的典型用法代码示例。如果您正苦于以下问题:Python Socket.is_open方法的具体用法?Python Socket.is_open怎么用?Python Socket.is_open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nanomsg.Socket
的用法示例。
在下文中一共展示了Socket.is_open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGeneralSocketMethods
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import is_open [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)
示例2: ServiceDiscovery
# 需要导入模块: from nanomsg import Socket [as 别名]
# 或者: from nanomsg.Socket import is_open [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()