加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

socket.error: [Errno 113] No route to host

(2014-09-07 08:40:18)
标签:

it

分类: Python
问题:防火墙。
关闭防火墙即可。 
#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:  
  
    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() 

客户端程序
[root@localhost ~]# cat c4.py
#coding=gbk  
import socket  
HOST = '192.168.1.16'    #IP地址为服务器IP
PORT = 8001
  
while True:  
    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() 

0

阅读 收藏 喜欢 打印举报/Report
前一篇:Shell Notes_001
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有