0
大家好,谢谢你审查我的问题!python tcpserver不要循环
我是新来的蟒蛇及继起的一本书教程中,我给她买,我在制作tcpserver
现在它为Python 2.x的书面我的股票,我知道我应该为3做。 x,但我想按照下面的说法开始,这是在书中解释!
这是他的一个普通的TCP服务器代码:
import socket
import threading
bind_ip = "0.0.0.0"
bind_port = 9999
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
server.listen(5)
print "[*] Listning on %s:%d" % (bind_ip,bind_port)
#this is our client-handling thread
def handle_client(client_socket):
#print out what the client sends
request = client_socket.recv(1024)
print "[*] Recived: %s" % request
#send back a packet
client_socket.send("ACK!")
client_socket.close()
while True:
client,addr = server.accept()
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1])
#spin up our client thread to handle incomming data
client_handler = threading.Thread(target=handle_client,args=(client,))
client_handler.start()
现在这个代码失败,当我从蟒蛇2.7.x运行它给我一个无效的语法% 所以我改变了一些线路的支持.format as%issent支持从我发现谷歌搜索周围!
print "[*] Listning on {0}:{1}".format(bind_ip,bind_port)
print "[*] Recived: {0}".format(request)
print "[*] Accepted connection from: {0}:{1}".format(addr[0],addr[1])
当我运行它,现在它吐出来:[*] Listning on 0.0.0.0:9999
很大吧? NO,因为某种原因,我无法弄清楚while循环不执行,因此爆发了的.py之后的第二次,所以我不能测试the tcp server script
我tcp client script
有人能告诉我什么我”错了吗?
显示与追溯完整的错误消息。同样,即使'格式'是实现它的新方法,仍然支持'%'格式。 –
对不起,浪费你的时间这个问题是我的行间距,我通常在php程序,这是不是空间大小写敏感causs括在括号内 – Ghostetr