Beispiel #1
0
	def send_data(self, sock, msg, mode = CommProto.MODE_ONCE, peer = None):
		with self.lock_:
			try:
				sock.send(CommProto.encode(msg))
				return True
			except:	# connection died, enqueue message if mode = MODE_SAFE
				Debug.print_stacktrace()
				enqueued = ''
				if mode == CommProto.MODE_SAFE:
					if not peer: return False
					print 'SEND FAILED, ENQUEUEING ...'
					if peer[0] in self.outgoing_q_:			# if in queue
						# append to queue
						self.outgoing_q_[peer[0]].append((msg, time.time()))
					else:
						# or create queue
						self.outgoing_q_[peer[0]] = [(msg, time.time())]
					enqueued = ', but saved in queue '
				self.remove_sock(sock)
				Logger.log('Socket died. Messag not sent%s...' % enqueued)
				return False
Beispiel #2
0
 def send_data(self, sock, msg, mode=CommProto.MODE_ONCE, peer=None):
     with self.lock_:
         try:
             sock.send(CommProto.encode(msg))
             return True
         except:  # connection died, enqueue message if mode = MODE_SAFE
             Debug.print_stacktrace()
             enqueued = ''
             if mode == CommProto.MODE_SAFE:
                 if not peer: return False
                 print 'SEND FAILED, ENQUEUEING ...'
                 if peer[0] in self.outgoing_q_:  # if in queue
                     # append to queue
                     self.outgoing_q_[peer[0]].append((msg, time.time()))
                 else:
                     # or create queue
                     self.outgoing_q_[peer[0]] = [(msg, time.time())]
                 enqueued = ', but saved in queue '
             self.remove_sock(sock)
             Logger.log('Socket died. Messag not sent%s...' % enqueued)
             return False
Beispiel #3
0
n = n or 1 # set number of requests to 1 if n not provided

if not (port and ip):
	# get port
	port = port or V_SETT.VISION_SRV_PORT
	ip = ip or ''	# '' is localhost

sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)

print "testclient: Connecting to [%s, %d] ..." % (ip, port)
sock.connect((ip, port))

if CommProto.CTR_PITCH in request:
	print 'ASKING PITCH'
	for i in range(n):
		sock.send(CommProto.encode([CommProto.CTR_PITCH, 0]))
		reply = recv(sock, COMMPROTO_MAX_MSG_SIZE)
		print "[%s, %d] Receiving: P[%d]" % (ip, port, i), reply

if CommProto.STATE in request:
	print 'Start streaming ...'
	# start stream
	sock.send(CommProto.encode([CommProto.CTR_STATE, 0]))
	i = 0
	for i in range(n):
		reply = recv(sock, COMMPROTO_MAX_MSG_SIZE)
		print "[%s, %d] Receiving: S " % (ip, port), reply
	# stop stream
	print 'Stopping stream ...'
	sock.send(CommProto.encode([CommProto.CTR_STOP_STATE, 0]))
	wait_ackn()
Beispiel #4
0
n = n or 1  # set number of requests to 1 if n not provided

if not (port and ip):
    # get port
    port = port or V_SETT.VISION_SRV_PORT
    ip = ip or ""  # '' is localhost

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

print "testclient: Connecting to [%s, %d] ..." % (ip, port)
sock.connect((ip, port))

if CommProto.CTR_PITCH in request:
    print "ASKING PITCH"
    for i in range(n):
        sock.send(CommProto.encode([CommProto.CTR_PITCH, 0]))
        reply = recv(sock, COMMPROTO_MAX_MSG_SIZE)
        print "[%s, %d] Receiving: P[%d]" % (ip, port, i), reply

if CommProto.STATE in request:
    print "Start streaming ..."
    # start stream
    sock.send(CommProto.encode([CommProto.CTR_STATE, 0]))
    i = 0
    for i in range(n):
        reply = recv(sock, COMMPROTO_MAX_MSG_SIZE)
        print "[%s, %d] Receiving: S " % (ip, port), reply
        # stop stream
    print "Stopping stream ..."
    sock.send(CommProto.encode([CommProto.CTR_STOP_STATE, 0]))
    wait_ackn()