Ruby에서 Python으로 변환하려고합니다. 루비 코드 : 나는 플러시 할 수있는 방법을 찾을 수 없습니다 socket.flushPython 소켓 시간 초과 및 플러시
여기
def read_byte begin Timeout.timeout(0.5) do b = socket.read 1 end rescue Timeout::Error => e socket.write("\n") socket.flush retry end end def socket @socket ||= TCPSocket.open @host, @port rescue SocketError # TODO: raise a specific error raise "Unable to open connection to #{@host} with given parameters" end
내 평균 문제입니다. 다른 어떤 방법으로이 작업을 수행 할 수 있습니까? 나는 이것을 썼다. 파이썬 코드 :
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self.host, self.port)) s.settimeout(0.5) while True: try: print s.recv(1) except socket.timeout: s.sendall("\n")
소켓을 플러시하여 이미'sendall()'을하지 않으려면 어떻게 될까요? – kindall
스트림이 내 코드에 다소 매달려 있습니다. 그것은 루비 코드와 함께 작동합니다. –