服务器单元拒绝连接我重置客户端计算机

发布于 2024-12-12 17:39:55 字数 1111 浏览 1 评论 0原文

下面是我在服务中运行的代码。在大多数情况下,脚本可以正常运行数天/数周,直到脚本出现问题并崩溃。我不太担心崩溃部分,因为我可以从错误日志中适当地解决补丁的原因。我面临的问题是,有时当服务重新启动并尝试再次连接到服务器时,它会收到 (10061, 'Connection returned') 错误,从而导致服务无法启动再次。奇怪的是,当连接被拒绝时,没有任何 python 进程在运行。 IE 中没有映像名称为“pythonw.exe”或“pythonservice.exe”的进程。应该注意的是,在重置运行客户端脚本的计算机之前,我也无法使用任何其他计算机连接到服务器。客户端计算机在 Windows Server 2003 操作系统上运行 python 2.7。还应该注意的是,服务器是在我无权访问代码的硬件上编码的。

try:            
        EthernetConfig = ConfigParser()
        EthernetConfig.read('Ethernet.conf')

        HOST = EthernetConfig.get("TCP_SERVER", "HOST").strip()
        PORT = EthernetConfig.getint("TCP_SERVER", "PORT")

        lp = LineParser()
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        s.connect((HOST, PORT))
        reader = s.makefile("rb")

        while(self.run == True):

            line = reader.readline()
            if line:
                line = line.strip()
                lp.parse(line)
except:

        servicemanager.LogErrorMsg(traceback.format_exc()) # if error print it to event log
        s.shutdown(2)
        s.close()
        os._exit(-1)

Below is the code I am running within a service. For the most part the script runs fine for days/weeks until the script hiccups and crashes. I am not so worried about the crashing part as I can resolve the cause from the error logs an patch appropriately. The issue I am facing is that sometimes when the service restarts and tries to connect to the server again, it gets a (10061, 'Connection refused') error, so that the service is unable to start up again. The bizarre part is that there is no python processes running when connections are being refused. IE no process with image name "pythonw.exe" or "pythonservice.exe." It should be noted that I am unable to connect to the server with any other machine as well until I reset computer which runs the client script. The client machine is running python 2.7 on a windows server 2003 OS. It should also be noted that the server is coded on a piece of hardware of which I do not have access to the code.

try:            
        EthernetConfig = ConfigParser()
        EthernetConfig.read('Ethernet.conf')

        HOST = EthernetConfig.get("TCP_SERVER", "HOST").strip()
        PORT = EthernetConfig.getint("TCP_SERVER", "PORT")

        lp = LineParser()
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        s.connect((HOST, PORT))
        reader = s.makefile("rb")

        while(self.run == True):

            line = reader.readline()
            if line:
                line = line.strip()
                lp.parse(line)
except:

        servicemanager.LogErrorMsg(traceback.format_exc()) # if error print it to event log
        s.shutdown(2)
        s.close()
        os._exit(-1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2024-12-19 17:39:55

连接被拒绝是一个错误,意味着连接另一端的程序不接受您的连接尝试。最有可能的是它没有注意到你崩溃了,也没有关闭它的连接。

您可以做的就是简单地休眠一会儿(30-60 秒),然后重试,并循环执行此操作,并希望另一端注意到连接已断开,以便它可以再次接受新连接。

Connection refused is an error meaning that the program on the other side of the connection is not accepting your connection attempt. Most probably it hasn't noticed you crashing, and hasn't closed its connection.

What you can do is simply sleep a little while (30-60 seconds) and try again, and do this in a loop and hope the other end notices that the connection in broken so it can accept new connections again.

放飞的风筝 2024-12-19 17:39:55

结果网络管理员关闭了我尝试连接的端口。对属于服务器的一个IP开放。问题是服务器有两个网卡,有两个独立的 IP。问题现已解决。

Turns out that Network Admin had the port closed that I was trying to connect to. It is open for one IP which belongs to the server. Problem is that the server has two network cards with two separate IP's. Issue is now resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文