"连接被重置"在Web浏览器尝试连接到本地主机套接字服务器时 [英] "The connection was reset" on web browsers when trying to connect to a localhost socket server

查看:286
本文介绍了"连接被重置"在Web浏览器尝试连接到本地主机套接字服务器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用,我可以连接到任何Web浏览器插座,蟒蛇的服务器。我使用的主机作为本地主机,端口为8888。

当我尝试连接到它,我想显示的东西显示出来的瞬间,然后将它与浏览器说:连接被重置消失结果
我将它做一些事情来测试,如果它仍然没有这很简单,它的作用。

有没有办法制止这种?

 导入时间
进口插座
HOST =本地主机
PORT = 8888高清功能(SCK):
    sck.send(字节(测试),UTF-8))
    sck.close()SSCK = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ssck.bind((主机,端口))
ssck.listen(1)
而真正的:
    SCK,地址= ssck.accept()
    功能(SCK)


解决方案

也许同样的问题<一href=\"http://stackoverflow.com/questions/24852821/perl-connection-reset-with-simple-http-server/24852907#24852907\">Perl:连接重置用简单的HTTP服务器,<一个href=\"http://stackoverflow.com/questions/33701177/ultra-simple-http-socket-server-written-in-php-behaving-unexpectedly/33701803#33701803\">Ultra简单的HTTP套接字服务器,用PHP编写的,不料的行为,<一个href=\"http://stackoverflow.com/questions/31168131/http-server-not-sending-complete-file-to-wget-firefox-connection-reset-by-peer/31168786#31168786\">HTTP服务器不发送完整的文件给wget,Firefox浏览器。将连接复位?。那是你不从浏览器中读取HTTP头,而只是发送您回应并关闭连接。

I am trying to make a server in python using sockets that I can connect to on any web browser. I am using the host as "localhost" and the port as 8888.

When I attempt to connect to it, the stuff I want to be shown shows up for a split-second, and then it goes away with the browser saying "The connection was reset".
I've made it do something very simple to test if it still does it, and it does.

Is there a way to stop this?

import time
import socket
HOST = "localhost"
PORT = 8888

def function(sck):
    sck.send(bytes("test"),"UTF-8"))
    sck.close()

ssck=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
ssck.bind((HOST,PORT))
ssck.listen(1)
while True:
    sck,addr=ssck.accept()
    function(sck)

解决方案

Probably the same problem as Perl: Connection reset with simple HTTP server, Ultra simple HTTP socket server, written in PHP, behaving unexpectedly, HTTP Server Not Sending Complete File To WGET, Firefox. Connection reset by peer?. That is you don't read the HTTP header from the browser but simply send your response and close the connection.

这篇关于&QUOT;连接被重置&QUOT;在Web浏览器尝试连接到本地主机套接字服务器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆