一段錯誤訊息
时间:2010-12-27
来源:互联网
- # -*- coding: utf-8 -*-
-
- import socket
- import asyncore
-
-
- servicePort = 443
-
-
- serviceHostAddress = 'ptt.cc'
- serviceHostPort = 443
-
- class AgentClient(asyncore.dispatcher_with_send):
-
- def __init__(self, otherSocket=None):
- asyncore.dispatcher_with_send.__init__(self, otherSocket)
-
-
- self.client = False
-
- self.ready = False
-
- self.other = None
-
- if not otherSocket:
- self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- else:
- self.client = True
-
- def handle_error(self):
-
-
- print "Error"
- self.handle_close()
-
- def handle_read(self):
-
-
- if self.other and self.other.ready:
- data = self.recv(4096)
-
- if data:
- self.other.send(data)
-
- def handle_connect(self):
-
-
- self.ready = True
- self.other.ready = True
-
- def handle_close(self):
-
-
- if self.client:
- print "Close connection from : " + self.socket.getpeername()[0]
-
- self.ready = False
- self.close()
- if self.other and self.other.ready:
- self.other.handle_close()
-
- class AgentServer(asyncore.dispatcher):
-
-
- def __init__(self, port):
- asyncore.dispatcher.__init__(self)
-
- self.port = port
- self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
- self.bind(('', self.port))
- self.listen(5)
-
- def handle_accept(self):
-
-
- clientSocket, address = self.accept()
- print 'New client from : ' + address[0]
-
- agentClient = AgentClient(clientSocket)
- agentHost = AgentClient()
-
-
- try:
- agentHost.connect((serviceHostAddress, serviceHostPort))
- except socket.error, (socketError, errorMessage):
- print 'Failed to connect %s : %s' % (serviceHostAddress, errorMessage)
- agentClient.handle_close()
- return
-
- agentHost.other = agentClient
- agentClient.other = agentHost
-
- def cleanSocketMapUp():
-
-
-
- # RuntimeError: dictionary changed size during iteration
- for fileno in asyncore.socket_map.keys():
- asyncore.socket_map[fileno].close()
-
- agentServer = AgentServer(servicePort)
- print "Agent is serving at %d and target to %s:%d ..." % (servicePort, serviceHostAddress, serviceHostPort)
- print "Press Ctrl + C to stop service."
-
- try:
- asyncore.loop(1)
- except KeyboardInterrupt:
- print "Stop agent service."
- finally:
- agentServer.close()
- cleanSocketMapUp()
下面是他出現錯誤,是nohup.out的紀錄請問下面這段訊息是什麼原因造成?
- 1 Agent is serving at 443 and target to ptt.cc:443 ...
- 2 Press Ctrl + C to stop service.
- 3 New client from : 114.35.133.52
- 4 New client from : 222.79.245.84
- 5 Error
- 6 Traceback (most recent call last):
- 7 File "ptt.py", line 106, in <module>
- 8 asyncore.loop(1)
- 9 File "/usr/lib/python2.6/asyncore.py", line 202, in loop
- 10 poll_fun(timeout, map)
- 11 File "/usr/lib/python2.6/asyncore.py", line 143, in poll
- 12 read(obj)
- 13 File "/usr/lib/python2.6/asyncore.py", line 80, in read
- 14 obj.handle_error()
- 15 File "ptt.py", line 34, in handle_error
- 16 self.handle_close()
- 17 File "ptt.py", line 55, in handle_close
- 18 print "Close connection from : " + self.socket.getpeername()[0]
- 19 File "<string>", line 1, in getpeername
- 20 socket.error: [Errno 107] Transport endpoint is not connected
作者: shihyu 发布时间: 2010-12-27
感觉像是socket已经断开了,不需要close了。
作者: nmweizi 发布时间: 2010-12-27
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28