diff -ur v7/sock_ut.py v8/sock_ut.py --- v7/sock_ut.py 2021-07-14 22:40:49.000000000 +0900 +++ v8/sock_ut.py 2021-07-16 10:25:21.000000000 +0900 @@ -11,6 +11,10 @@ can_read = lambda sc, tmout=0: select.select( [ sc ], [], [], tmout )[ 0 ] == [ sc ] +add_tail = lambda s, add: s + add + +cut_tail = lambda s, cut: s[ : -len( cut ) ] if s.endswith( cut ) else s + def port_conn( port, host='localhost' ): cs = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) try: @@ -40,16 +44,19 @@ return buf def send_str( sc, s ): + s = add_tail( s, '\n' ) bt = s.encode( 'utf-8' ) return send_bt( sc, bt ) def recv_str( sc, bufmax=16*1024 ): - bt = recv_bt( sc, bufmax ) - return bt.decode( 'utf-8' ) + bt = recv_bt( sc, bufmax + 1 ) # '\n' + s = bt.decode( 'utf-8' ) + return cut_tail( s, '\n' ) def recv_str_all( sc ): bt = recv_bt_all( sc ) - return bt.decode( 'utf-8' ) + s = bt.decode( 'utf-8' ) + return cut_tail( s, '\n' ) def pipe_loop( sc_from, sc_to ): while True: