def take(self, _msgLen = 2048): if not self._socket: return "" chunks = [] bytes_recd = 0 while bytes_recd < _msgLen: chunk = None try: chunk = self._socket.recv(min(_msgLen - bytes_recd, 2048)) except: break # if chunk == '': # break #raise RuntimeError("socket connection broken") if chunk: chunks.append(chunk) bytes_recd = bytes_recd + len(chunk) if not chunk: break return mjcIMsg.mjcMessage1(''.join(chunks))
def take(self, _msgLen=2048): if not self._socket: return "" chunks = [] bytes_recd = 0 while bytes_recd < _msgLen: chunk = None try: chunk = self._socket.recv(min(_msgLen - bytes_recd, 2048)) except: break # if chunk == '': # break #raise RuntimeError("socket connection broken") if chunk: chunks.append(chunk) bytes_recd = bytes_recd + len(chunk) if not chunk: break return mjcIMsg.mjcMessage1(''.join(chunks))
def test_run_msg1_leavesQueueEmpty(m_class): import time xBody = "ABC" msg = mjcIMsg.mjcMessage1(xBody) y = m_class.send(msg) msg = mjcIMsg.done() y = m_class.send(msg) m_class.shutdown() time.sleep(0.5) z = m_class.qIn() a1 = z.take() if (a1): a1 = a1.body assert a1 == None
def _run(self): # bind the socket to a public host, print("Bind to {}/{}".format(self._host, self._port)) self._serversocket.bind((self._host, self._port)) # become a server socket self._serversocket.listen(1) (self._clientsocket, self._address) = self._serversocket.accept() # now do something with the clientsocket if not self._clientsocket: return # just print out what the client sends request = self._clientsocket.recv(1024) print "[*] Received: %s" % request if self.qIn(): self.qIn().put(mjcMessage1("{}".format(request))) if self._clientsocket: print("getpeername {}".format(self._clientsocket.getpeername())) # send back a packet ack = "ACK!" # ack = None if ack: self._clientsocket.sendall(ack) if ack and self.qOut(): self.qOut().put(mjcMessage1(ack)) if self._clientsocket: self._clientsocket.close() self._clientsocket = None if self._serversocket: self._serversocket.close() self._serversocket = None print("run finished")
def _run(self): # bind the socket to a public host, print("Bind to {}/{}".format(self._host, self._port)) self._serversocket.bind((self._host, self._port)) # become a server socket self._serversocket.listen(1) (self._clientsocket, self._address) = self._serversocket.accept() # now do something with the clientsocket if not self._clientsocket: return # just print out what the client sends request = self._clientsocket.recv(1024) print "[*] Received: %s" % request if self.qIn(): self.qIn().put(mjcMessage1("{}".format(request))) if self._clientsocket: print("getpeername {}".format(self._clientsocket.getpeername())) # send back a packet ack = "ACK!" # ack = None if ack: self._clientsocket.sendall(ack) if ack and self.qOut(): self.qOut().put(mjcMessage1(ack)) if self._clientsocket: self._clientsocket.close() self._clientsocket = None if self._serversocket: self._serversocket.close() self._serversocket = None print("run finished")
def _run(self): # bind the socket to a public host, self._serversocket.bind((self._host, self._port)) # become a server socket self._serversocket.listen(1) ### while True: print("while-") (self._clientsocket, self._address) = self._serversocket.accept() # now do something with the clientsocket if not self._clientsocket: print("No socket accepted") break if not self._qIn: raise "msgQueue not defined" request = self._clientsocket.recv(1024, ) msgPtr = mjcIMsg.mjcMessage1(request) if msgPtr: self.body.append(msgPtr.body) #self._x = True ret = msgPtr.execute() if ret and self._qOut: self._qOut.put(ret) if msgPtr.body == self._DONE.body: break time.sleep(0.25) ### # just print out what the client sends # request = self._clientsocket.recv(1024) # print "[*] Received: %s" % request # self._qIn.put("{}".format(request)) # send back a packet # self._clientsocket.send("ACK!") # print self._clientsocket.getpeername() if self._clientsocket: self._clientsocket.close() if self._serversocket: self._serversocket.close() print("run finished")
def _run(self): # bind the socket to a public host, self._serversocket.bind((self._host, self._port)) # become a server socket self._serversocket.listen(1) ### while True: print("while-") (self._clientsocket, self._address) = self._serversocket.accept() # now do something with the clientsocket if not self._clientsocket: print("No socket accepted") break if not self._qIn: raise "msgQueue not defined" request = self._clientsocket.recv(1024,) msgPtr = mjcIMsg.mjcMessage1(request) if msgPtr: self.body.append(msgPtr.body) #self._x = True ret = msgPtr.execute() if ret and self._qOut: self._qOut.put(ret) if msgPtr.body == self._DONE.body: break time.sleep(0.25) ### # just print out what the client sends # request = self._clientsocket.recv(1024) # print "[*] Received: %s" % request # self._qIn.put("{}".format(request)) # send back a packet # self._clientsocket.send("ACK!") # print self._clientsocket.getpeername() if self._clientsocket: self._clientsocket.close() if self._serversocket: self._serversocket.close() print("run finished")
def test_take2_Fail(m_class): xBody = "ABC" msg = mjcIMsg.mjcMessage1(xBody) assert True == m_class.put(msg) x = m_class.take() x = m_class.take() assert None == x
def test_take2_Fail(m_class): xBody = "ABC" msg = mjcIMsg.mjcMessage1(xBody) assert True == m_class.put(msg) x = m_class.take() x = m_class.take() assert None == x
def test_take1_OK(m_class): xBody = "ABC" msg = mjcIMsg.mjcMessage1(xBody) assert True == m_class.put(msg) x = m_class.take() assert isinstance(x, mjcIMsg.mjcMessage1) assert xBody == x.body
def test_take1_OK(m_class): xBody = "ABC" msg = mjcIMsg.mjcMessage1(xBody) assert True == m_class.put(msg) x = m_class.take() assert isinstance(x, mjcIMsg.mjcMessage1) assert xBody == x.body
def take(self, _msgLen): chunks = [] bytes_recd = 0 while bytes_recd < _msgLen: chunk = self.sock.recv(min(_msgLen - bytes_recd, 2048)) if chunk == '': raise RuntimeError("socket connection broken") chunks.append(chunk) bytes_recd = bytes_recd + len(chunk) return mjcIMsg.mjcMessage1(''.join(chunks))
def take(self, _msgLen): chunks = [] bytes_recd = 0 while bytes_recd < _msgLen: chunk = self.sock.recv(min(_msgLen - bytes_recd, 2048)) if chunk == '': raise RuntimeError("socket connection broken") chunks.append(chunk) bytes_recd = bytes_recd + len(chunk) return mjcIMsg.mjcMessage1(''.join(chunks))
def test_done_stops_process(m_class): # import time x = mjcIMsg.mjcMessage1("ABC") m_class.send(x) x = mjcIMsg.done() m_class.send(x) # time.sleep(1) a = m_class.isAlive(); m_class.shutdown() assert a == False
def test_create_created(m_class): global host, port # (host, port) = ("127.0.0.1", 62029) # qIn = mjcMsgQ.mjcMsgQ() # qOut = mjcMsgQ.mjcMsgQ() # server = mjcSockListen1.create(qIn, qOut, host, port) assert m_class != None client = mjcMsgQSocket.createSender(host, port) msg = mjcIMsg.mjcMessage1("ABC") client.put(msg) client.shutdown() m_class.shutdown()
def test_create_created(m_class): global host, port # (host, port) = ("127.0.0.1", 62029) # qIn = mjcMsgQ.mjcMsgQ() # qOut = mjcMsgQ.mjcMsgQ() # server = mjcSockListen1.create(qIn, qOut, host, port) assert m_class != None client = mjcMsgQSocket.createSender(host, port) msg = mjcIMsg.mjcMessage1("ABC") client.put(msg) client.shutdown() m_class.shutdown()
def test_create_created(m_class): global host, port # (host, port) = ("127.0.0.1", 62029) # qIn = mjcMsgQ.mjcMsgQ() # qOut = mjcMsgQ.mjcMsgQ() # server = mjcSockListen1.create(qIn, qOut, host, port) assert m_class != None msg = mjcIMsg.mjcMessage1("ABC") m_class.send(msg) msg = mjcIMsg.done() m_class.send(msg) m_class.shutdown()