检索类型错误:"NoneType"对象不是可调用的套接字



我有以下代码从客户端1发送帧,从客户端1向客户端3发送数据。

客户端-1代码

context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.connect('tcp://172.168.1.2:5555')
videoFile = 'data.mp4'
camera = cv2.VideoCapture(videoFile) 
length=int(camera.get(cv2.CAP_PROP_FRAME_COUNT))
while True:        
grabbed, frame = camera.read()
try:
frame = cv2.resize(frame, (224, 224))
except cv2.error:
break
encoded, buffer = cv2.imencode('.jpg', frame)
jpg_as_text = base64.b64encode(buffer)
footage_socket.send(jpg_as_text)

客户端-2代码

footage_socket = context.socket( zmq.SUB )
footage_socket.bind('tcp://0.0.0.0:5555')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
PUB_TARGET = 'tcp://192.168.56.103:9999'
while True:    
frame  = footage_socket.recv_string()                         
source = cv2.imdecode( np.fromstring( base64.b64decode( frame ), dtype = np.uint8),1 )
frame  = cv2.resize( source,
(224,224)
).astype( "float32" )
image = img_to_array( source )
image = image.reshape( ( 1,image.shape[0],image.shape[1], image.shape[2]))
preds = model.predict( preprocess_input( image ) )
## connecting to server #######
context1=zmq.Context()                          
footage_socket = context1.socket( zmq.PUB )      
footage_socket.connect( PUB_TARGET )            
footage_socket.send(preds)

服务器1代码:

context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://0.0.0.0:9999')
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
while True:
frame = footage_socket.recv_string()
img = base64.b64decode(frame)
print(img)

在运行上述代码时,我正在检索客户端2代码中的错误

frame = footage_socket.recv_string()p
File "/usr/local/lib/python3.5/dist-packages/zmq/sugar/socket.py", line 583, in recv_string
msg = self.recv(flags=flags)
zmq.error.ZMQError: Operation not supported
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session 
object at 0x7fa8c6a50908>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 707, in __del__
TypeError: 'NoneType' object is not callable

在尝试接收之前,您需要在客户端2中连接或绑定套接字。

footage_socket = context.socket( zmq.SUB )
>>> CONNECT OR BIND <<<<
PUB_TARGET = 'tcp://192.168.56.103:9999'
while True:    
frame  = footage_socket.recv_string()                         

最新更新