本文整理汇总了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)
示例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
示例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()
示例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