Python套接字抛出多个异常

时间:2016-03-15 14:56:15

标签: python sockets

我们的代码在python 2.4.2上,在嵌入式Linux环境(ARM)中。

当尝试获取套接字连接并且服务器拒绝连接时,我会收到多个错误。

第一个是socket.error - 连接被拒绝。这是在异常块中处理的。

在来电者获得例外'数据'

之后

相关代码是:

class CTM_TX_Service(object):

    def __init__(self, synch):
        """ Create a new CTM_TX_SERVICE.
        """
        global gSynch

        gSynch = synch
        gSynch.logDebug("CTM TX SERVICE init")
        self.synch=synch

    def send(self, data, IP, port=CTM_CMD_PORT):
        try:
            gSynch.logDebug("CTM TX SERVICE sending message " + str(data))
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            socket.setdefaulttimeout(3.0) #wait for 3 second before timeout
            s.connect((IP, port))
            s.send(data)
            reply = s.recv(1024)
            s.close()
        except Exception, e:
            gSynch.logError("CTM TX Send exception: "+str(e))

来电者的密码:

def SendOperatingMode(self, mode):
    self.TrouncerListLock.acquire()
    for interface in self.activeTrouncerList:
        try:
            cmd = "mode %d" % mode
            ip = interface['ip']
            self.synch.logInfo("Send CTM command: '%s' to IP %s" % (cmd, ip))
            self.synch.ctmTx.send(cmd, ip)
        except Exception, e:
            self.synch.logError("SendOperatingMode exception: %s" % str(e))
    self.synch.logDebug("SetMode done")
    self.TrouncerListLock.release()

以及相应的日志:

Aug  6 21:49:38 TROUNCER user.info Synch: Send CTM command: mode 0 to IP 192.168.11.13
Aug  6 21:49:38 TROUNCER user.debug Synch: CTM TX SERVICE sending message mode 0
Aug  6 21:49:39 TROUNCER user.info Synch: Send CTM command: mode 0 to IP 192.168.10.12
Aug  6 21:49:39 TROUNCER user.debug Synch: CTM TX SERVICE sending message mode 0
Aug  6 21:49:39 TROUNCER user.err Synch: CTM TX Send exception: (111, 'Connection refused')
Aug  6 21:49:39 TROUNCER user.err Synch: SendOperatingMode exception: 'data'
Aug  6 21:49:40 TROUNCER local7.notice dvcs: cSpd,   373: Flagging Server Down: 192.168.11.26:49152 

最后一条日志消息"设置模式已完成"从来没有见过让我相信来电者的功能也会在结束之前退出。

0 个答案:

没有答案