def _receiveConsoleOutput(self): """ This function receives and prints console output Input: Nothing Returns: Nothing """ import sys from comm import protocol, sendAndReceive, CommClientException while True: if self._exit.is_set(): break try: frame = sendAndReceive(self._ip,self._port,protocol.frame(prc.PRC_OUTPUT,self._session_id)) except CommClientException as error: self._exit.set() raise PRCClientException("Connection problem: " + str(error)) cmd,data = protocol.analyze(frame) if cmd == prc.PRC_OUTPUT: sys.stdout.write(data) elif cmd == prc.PRC_CONFIRM: self._synch.release() elif cmd == prc.PRC_EXIT: self._synch.release() self._exit.set()
def _start_session(self): """ This function starts PRC session Input: Nothing Returns: Nothing """ from comm import protocol, sendAndReceive, CommClientException try: sendAndReceive(self._ip,self._port,protocol.frame(prc.PRC_NEW_SESSION,self._session_id)) except CommClientException as error: self._exit.set() raise PRCClientException("Connection problem: " + str(error))
def _prompt(self): """ This function gets prompt from server Input: Nothing Returns: prompt """ from comm import protocol, sendAndReceive, CommClientException try: frame = sendAndReceive(self._ip,self._port,protocol.frame(prc.PRC_PROMPT,self._session_id)) except CommClientException as error: self._exit.set() raise PRCClientException("Connection problem: " + str(error)) cmd,prompt = protocol.analyze(frame) self._synch.acquire() return prompt
def _sendConsoleInput(self,data): """ This function sends command. Blocking funnction. Input: data - Input python command Returns: Nothing """ from comm import protocol, sendAndReceive, CommClientException try: frame = sendAndReceive(self._ip,self._port,protocol.frame(prc.PRC_CODE,(self._session_id,data))) except CommClientException as error: self._exit.set() raise PRCClientException("Connection problem: " + str(error)) self._synch.acquire() cmd,data = protocol.analyze(frame) if cmd == prc.PRC_EXIT: raise SystemExit
from comm import sendAndReceive ip = "127.0.0.1" port = 59899 data = "".join(["a"]*(4096*1000+55)) sendAndReceive(ip,port,data)