本文整理汇总了Python中zmqpy.Context.socket方法的典型用法代码示例。如果您正苦于以下问题:Python Context.socket方法的具体用法?Python Context.socket怎么用?Python Context.socket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmqpy.Context
的用法示例。
在下文中一共展示了Context.socket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_socket_connected_recv
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_connected_recv(self):
from zmqpy import Context, PAIR
from zmqpy._cffi import zmq_version
c = Context()
sender = c.socket(PAIR)
receiver = c.socket(PAIR)
bind = receiver.bind('tcp://*:3333')
connect = sender.connect('tcp://127.0.0.1:3333')
assert bind == 0
assert connect == 0
ret = sender.send("zmqpy test message")
if zmq_version == 2:
assert ret == 0
else:
assert ret == 18
assert sender.last_errno == None
import time
time.sleep(0.2)
message = receiver.recv()
assert sender.last_errno == None
assert message == "zmqpy test message"
sender.close()
receiver.close()
示例2: test_socket_connected_recv
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_connected_recv(self):
from zmqpy import Context, PAIR
c = Context()
sender = c.socket(PAIR)
receiver = c.socket(PAIR)
bind = receiver.bind("tcp://*:3333")
connect = sender.connect("tcp://127.0.0.1:3333")
assert bind == 0
assert connect == 0
ret = sender.send("zmqpy test message")
assert ret == 0
assert sender.last_errno == None
import time
time.sleep(0.2)
message = receiver.recv()
assert sender.last_errno == None
assert message == "zmqpy test message"
sender.close()
receiver.close()
示例3: test_socket_connect
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_connect(self):
from zmqpy import Context, PAIR
c = Context()
sender = c.socket(PAIR)
receiver = c.socket(PAIR)
bind = receiver.bind('tcp://*:3333')
assert bind == 0
connect = sender.connect('tcp://127.0.0.1:3333')
assert connect == 0
sender.close()
receiver.close()
示例4: test_socket_setsockopt_int
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_setsockopt_int(self):
from zmqpy import Context, PAIR, ZMQ_LINGER
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(ZMQ_LINGER, 10)
assert rc == 0
sender.close()
示例5: test_socket_setsockopt_int64
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_setsockopt_int64(self):
from zmqpy import Context, PAIR, ZMQ_RATE
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(ZMQ_RATE, 200)
assert rc == 0
sender.close()
示例6: test_socket_setsockopt_binary
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_setsockopt_binary(self):
from zmqpy import Context, PAIR, ZMQ_IDENTITY
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(ZMQ_IDENTITY, "id")
assert rc == 0
sender.close()
示例7: test_socket_connected_send
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_connected_send(self):
from zmqpy import Context, PAIR
c = Context()
sender = c.socket(PAIR)
receiver = c.socket(PAIR)
bind = receiver.bind("tcp://*:3333")
connect = sender.connect("tcp://127.0.0.1:333")
ret = sender.send("zmqpy test message")
assert ret == 0
assert sender.last_errno == None
sender.close()
receiver.close()
示例8: test_socket_bind
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_bind(self):
from zmqpy import Context, PAIR
c = Context()
socket = c.socket(PAIR)
bind = socket.bind('tcp://*:3333')
assert bind == 0
socket.close()
示例9: test_context_socket
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_context_socket(self):
from zmqpy import Context, PAIR
c = Context()
socket = c.socket(PAIR)
assert socket
assert c.n_sockets == 1
assert len(c._sockets) == 1
assert not c.closed
示例10: test_socket_disconnected_send
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_disconnected_send(self):
from zmqpy import Context, PAIR, NOBLOCK
c = Context()
socket = c.socket(PAIR)
ret = socket.send("zmqpy test message", NOBLOCK)
assert ret == -1
assert socket.last_errno > 0
socket.close()
示例11: test_socket_getsockopt_binary
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_getsockopt_binary(self):
from zmqpy import Context, PAIR, ZMQ_IDENTITY
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(ZMQ_IDENTITY, "id")
assert rc == 0
opt_value = sender.getsockopt(ZMQ_IDENTITY, length=2)
assert opt_value != -1
assert opt_value == "id"
sender.close()
示例12: test_socket_getsockopt_int64
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_getsockopt_int64(self):
from zmqpy import Context, PAIR, RATE
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(RATE, 200)
assert rc == 0
opt_value = sender.getsockopt(RATE)
assert opt_value != -1
assert opt_value == 200
sender.close()
示例13: test_socket_getsockopt_int
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_getsockopt_int(self):
from zmqpy import Context, PAIR, LINGER
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(LINGER, 10)
assert rc == 0
opt_value = sender.getsockopt(LINGER)
assert opt_value != -1
assert opt_value == 10
sender.close()
示例14: test_socket_connected_send
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_connected_send(self):
from zmqpy import Context, PAIR
from zmqpy._cffi import zmq_version
c = Context()
sender = c.socket(PAIR)
receiver = c.socket(PAIR)
bind = receiver.bind('tcp://*:3333')
connect = sender.connect('tcp://127.0.0.1:333')
message = "zmqpy test message"
ret = sender.send(message)
if zmq_version == 2:
assert ret == 0
else:
assert ret == len(message)
assert sender.last_errno == None
sender.close()
receiver.close()
示例15: test_socket_getsockopt_uint64
# 需要导入模块: from zmqpy import Context [as 别名]
# 或者: from zmqpy.Context import socket [as 别名]
def test_socket_getsockopt_uint64(self):
from zmqpy import Context, PAIR, ZMQ_HWM
c = Context()
sender = c.socket(PAIR)
rc = sender.setsockopt(ZMQ_HWM, 10)
assert rc == 0
opt_value = sender.getsockopt(ZMQ_HWM)
assert opt_value != -1
assert opt_value == 10
sender.close()