def java_utf8_message_dispatcher(buffer): byte_array = [buffer.get_byte(i) for i in range(buffer.length)] byteArrayInputStream = ByteArrayInputStream(byte_array) dataInputStream = DataInputStream(byteArrayInputStream) while dataInputStream.available() > 0: try: yield dataInputStream.readUTF() except: pass
if len(sys.argv) < 3: print "You need to specify the host and port, in that order, to" print "connect to." sys.exit() print "Connecting..." socket = Socket(sys.argv[1], int(sys.argv[2])) print "Connected! One moment..." in_stream = DataInputStream(socket.getInputStream()) out_stream = DataOutputStream(socket.getOutputStream()) try: while not socket.isClosed(): mode = in_stream.readShort() if mode == 2: # normal text write sys.stdout.write(in_stream.readUTF()) sys.stdout.flush() elif mode == 3: # raw_input with prompt result = raw_input(in_stream.readUTF()) out_stream.writeUTF(result); out_stream.flush() elif mode == 4: # Exiting break else: print "Invalid mode received: " + str(mode) break except: print "Connect exception:" print_exc() if not socket.isClosed():