无法连接到 Windows 上的本地服务器
Can't connect to local server on Windows
我的服务器应用程序使用POCO库用C++编写时遇到了一个奇怪的问题。它运行良好,几天前刚刚停止工作。即使使用两周前的exe也不起作用。
问题是,我无法通过localhost连接到服务器,但来自我网络之外的其他人可以毫无问题地连接。。。
我在其他电脑上测试过,除了一台电脑外,其他电脑都是一样的。该问题仅在Windows上存在。我在Linux上进行了测试,它运行良好。
该问题也在POCO教程的代码中重现http://pocoproject.org/slides/200-Network.pdf:
#include "Poco/Net/ServerSocket.h"
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/SocketAddress.h"
int main(int argc, char** argv)
{
Poco::Net::ServerSocket srv(8080); // does bind + listen
for (;;)
{
Poco::Net::StreamSocket ss = srv.acceptConnection();
Poco::Net::SocketStream str(ss);
str << "HTTP/1.0 200 OKrn"
"Content-Type: text/htmlrn"
"rn"
"<html><head><title>My 1st Web Server</title></head>"
"<body><h1>Hello, world!</h1></body></html>"
<< std::flush;
}
return 0;
}
在Chrome中输入127.0.0.1:8080会导致ERR_CONNECTION_ABORTED。http://www.canyouseeme.org/报告它可以在8080端口上看到我的服务。
其他应用程序(不使用POCO I guess?)运行良好。
我完全不知道这个问题的原因是什么。。。如果有任何建议,我将不胜感激。
我试过你的例子。这看起来很正常。如果它过去是有效的,那么它就不正常了。可能是,你已经更新了Chrome浏览器,或者之前用一些旧浏览器测试过吗?
在该示例中,服务器正在发送数据并立即关闭连接。我认为,POCO中应该有一个命令,以任何更优雅的方式终止连接。
该示例似乎演示了非常简单但不符合协议的服务器响应。请尝试使用HTTPRequestHandlerFactory。这样,服务器似乎不会在每次请求后终止连接。
Firefox显示非常短的"Hello World!">,然后显示"连接中止">
Chrome中的ERR_CONNECTION_ABORTED
可能也意味着服务器意外关闭了连接。
卷曲显示在大多数情况下:
C:bin>curl.exe http://localhost:8080
curl: (56) Recv failure: Connection was reset
但在一些罕见的情况下:
C:bin>curl.exe http://localhost:8080
<html><head><title>My 1st Web Server</title></head><body><h1>Hello, world!</h1></body></html>
curl: (56) Recv failure: Connection was reset
在flush
之后添加了Sleep(100)
之后,html内容总是显示在Recv failure
之前。因此,取决于浏览器是否显示内容的时间。
可能有关于linux上不同行为的提示:
void HTTPServerConnection::onServerStopped(const bool& abortCurrent)
{
_stopped = true;
if (abortCurrent)
{
try
{
// Note: On Windows, select() will not return if one of its socket is being
// shut down. Therefore we have to call close(), which works better.
// On other platforms, we do the more graceful thing.
#if defined(_WIN32)
socket().close();
#else
socket().shutdown();
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 在 c++ 中检查 Windows OS 服务器版本
- 由非托管(C++)COM服务器实例化的托管(C#)控件在Windows更新后损坏
- 连接到IRC服务器C++Windows 10 Visual Studio
- 堆损坏对 Windows 2012 r2 服务器的影响
- 在C 中将多个客户端连接到Windows中的单个服务器中的多线程
- 如何检测端口是否已在服务器端使用(在windows上的C++中)
- Windows,C++:一个服务器套接字上有两个连接
- 在服务器上执行命令,然后将结果发送到Windows中的客户端
- Windows HTTP服务器API HTTPS服务器
- 节俭 TNonblocking服务器.cpp未声明的标识符 - Windows
- 从 SharePoint 2010 服务器下载,在 Windows 客户端上的本地应用程序中打开
- 在cygwin(windows)和gcc/g++mac中的udp客户端服务器
- Linux服务器和Windows客户端上的C 源代码
- MySQL Windows c api 命名管道错误:"在'等待初始通信数据包'时丢失与 MySQL 服务器的连接,系统错误:0
- 使用SNTP(Windows C )从服务器获取时间/日期
- Unix 服务器 - Windows 客户端,连接失败
- 在Windows 2008 R2服务器/ Windows 7中,判断谁正在访问共享文件夹中的文件
- 当与服务器的连接超过1个时,c++tcp服务器(windows操作系统)-recv()会延迟
- 在远程Windows服务器(Windows Vista或更高版本)上捕获屏幕