socket.error: [Errno 113] No route to host
(2014-09-07 08:40:18)
标签:
it |
分类: Python |
问题:防火墙。
thistime=time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime())
try:
connection,address = sock.accept()
connection.settimeout(5)
buf =
connection.recv(1024)
print (thistime+"received"+buf+"")
connection.send(thistime+':'+buf)
except socket.timeout:
print 'time out'
connection.close()
temp=raw_input("Please
input the character you want to send:")
if temp=="exit":
break
s =
socket.socket(socket.AF_INET, socket.SOCK_STREAM)
strd=temp+""
s.connect((HOST, PORT))
s.send(strd+"")
data = s.recv(1024)
print data
s.close()
关闭防火墙即可。
#service iptables stop
服务器端程序
[root@localhost ~]# cat s4.py
#coding=utf8
#pythonsocket
import socket
import time
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('192.168.1.16',8001))
#IP地址为服务器IP
sock.listen(5)
while True:
客户端程序
[root@localhost ~]# cat c4.py
#coding=gbk
import socket
HOST = '192.168.1.16'
#IP地址为服务器IP
PORT = 8001
while True: