谁能告诉我如何摆脱其中的换行符?每次回显字符串时,都会有一个换行符。基本上是一个空字符。我怎样才能摆脱它?
from socket import *
import threading
import thread
def handler(clientsock,addr):
while 1:
data = clientsock.recv(BUFSIZ)
if not data:
break
msg = data
print msg
clientsock.send(msg)
clientsock.close()
if __name__=='__main__':
host = 'localhost'
port = 20000
BUFSIZ = 1024
ADDR = (host, port)
serversock = socket(AF_INET, SOCK_STREAM)
serversock.bind(ADDR)
serversock.listen(2)
print 'Version 0.1','-',host,':',port
while 1:
clientsock, addr = serversock.accept()
print 'initiated',addr[0],'on',addr[1]
thread.start_new_thread(handler, (clientsock, addr))