tcp服务端监听端口长时间后会失效

gnorth 2017-06-02 10:58:45
用的是阿里云的服务器,这个问题我不是第一次发现了,这个周期长的时候几个月一次,短的话也是最少一个月,不单单是我自己的服务端,微软的netsh,也是长时间后会失效,有人遇到过这种问题吗?
...全文
1983 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
iTom 2020-12-28
  • 打赏
  • 举报
回复
请问楼主你这个问题最后实锤了么 我也遇到这个问题,阿里云服务器tcp server端口在运行一段时间后,新连接进不来,netstat查看端口在监听,但是本地都telnet不通。。。。
smwhotjay 2017-10-25
  • 打赏
  • 举报
回复
解决办法 1.写个客户端监控,比如每分钟连一次,如果都连不上,则重启服务端。
danscort2000 2017-10-25
  • 打赏
  • 举报
回复
引用 6 楼 euber2 的回复:
在windows下,Listen函数会在网线拔掉(网路不可用)后,失效。
你确定会这样? 我怎么没测试到有这样的情况发生呢? 只要bind null也就是本机所有ip地址 即使拔掉网线,或者干脆换ip 都不会有问题,新的ip设置后同样会自动绑定 除非你绑定了指定的ip地址,然后这个ip被换掉才会出现失败 问题是服务器端,没有什么人会绑定一个指定IP的吧,一般都是全绑定
赵4老师 2017-09-28
  • 打赏
  • 举报
回复
引用 6 楼 euber2 的回复:
在windows下,Listen函数会在网线拔掉(网路不可用)后,失效。
代码添加判断如果失效,等条件允许的时候,重新listen
smwhotjay 2017-09-27
  • 打赏
  • 举报
回复
GetTickCount 别人试 貌似40多天就溢出了。很大的数 溢出成最小,程序逻辑就跪了。要么使用GetTickCount64 范围增大,时间更长。要么用别的api
euber2 2017-09-26
  • 打赏
  • 举报
回复
在windows下,Listen函数会在网线拔掉(网路不可用)后,失效。
danscort2000 2017-06-29
  • 打赏
  • 举报
回复
会不会是你的服务器端软件, 采用的是老的xp时期的APM广播消息来阻止服务器进入休眠状态? 这样你服务器端如果一直繁忙那么没问题,但是如果期间有一段时间无连接 服务器会被强制进入休眠状态的
kakabulusi 2017-06-08
  • 打赏
  • 举报
回复
正常来讲,不会出现这种情况。 如果出现了这种情况,建议写个超时启机制。
赵4老师 2017-06-08
  • 打赏
  • 举报
回复
十有八九和这个API有关: GetTickCount The GetTickCount function retrieves the number of milliseconds that have elapsed since the system was started. It is limited to the resolution of the system timer. If you need a higher resolution timer, use amultimedia timer or a high-resolution timer. DWORD GetTickCount(VOID) Parameters This function has no parameters. Return Values The return value is the number of milliseconds that have elapsed since the system was started. Remarks The following table describes the resolution of the system timer. System Resolution Windows NT 3.5 and later The system timer runs at approximately 10ms. Windows NT 3.1 The system timer runs at approximately 16ms. Windows 95 and later The system timer runs at approximately 55ms. The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. Windows NT: To obtain the time elapsed since the computer was started, look up the System Up Time counter in the performance data in the registry key HKEY_PERFORMANCE_DATA. The value returned is an 8-byte value. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Requires version 1.0 or later. Header: Declared in winbase.h. Import Library: Use kernel32.lib. See Also Time Overview, Time Functions 仅供参考:
#pragma comment(lib,"ntdll")
#pragma comment(lib,"user32")
#include <afxdisp.h>
#include <windows.h>
#include <winnt.h>
#include <stdio.h>
#include <memory.h>
#include <math.h>
BOOL r;
extern "C" NTSYSAPI NTAPI NtQuerySystemInformation(
    IN  UINT   SystemInformationClass,  // 信息类型
    OUT PVOID  SystemInformation,       // 缓冲指针
    IN   ULONG SystemInformationLength, // 缓冲的字节大小
    OUT PULONG ReturnLength OPTIONAL    // 写入缓冲的字节数
);
//第一个参数是请求的信息类型。这个参数可以有许多值。为了得到系统启动时间,我们只用其中的一个值:SystemTimeInformation(3)。
//如果,第一个参数是SystemTimeInformation,则第二个参数必须是一个SYSTEM_TIME_INFORMATION结构指针。
typedef struct {
    LARGE_INTEGER liKeBootTime;//系统被启动的时间(以1/10000毫秒计)。
    LARGE_INTEGER liKeSystemTime;
    LARGE_INTEGER liExpTimeZoneBias;
    ULONG         uCurrentTimeZoneId;
    DWORD         dwReserved;
} SYSTEM_TIME_INFORMATION;
SYSTEM_TIME_INFORMATION sti;
ULONG rl;
ULONG tk;
FILETIME ft;
//SYSTEMTIME lt;
//extern "C" ULONGLONG WINAPI GetTickCount64(void);
//ULONGLONG tk64;
ULONGLONG d497;
#define days_of_2_32ms 49.71026962962962962962962962963 //(2^32)/24/60/60/1000=49.71026962962962962962962962963
int main() {
    NtQuerySystemInformation(3,&sti,sizeof(sti),&rl);//3==SystemTimeOfDayInformation
    COleDateTime t,now;
    CString s,fmt="%Y-%m-%d %H:%M:%S";

    memcpy(&ft,&sti.liKeBootTime,sizeof(LARGE_INTEGER));
    t=COleDateTime(ft);
    s=t.Format(fmt);
    printf("                            Boot DateTime: %s\n",s);
    tk=GetTickCount();//The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days.
    now=COleDateTime::GetCurrentTime();
    t=now-COleDateTimeSpan((double)tk/86400000.0);
    s=t.Format(fmt);
    printf("Prev GetTickCount() Wrap to Zero DateTime: %s\n",s);
    s=now.Format(fmt);
    printf("     GetTickCount():%08X,Now DateTime: %s\n",tk,s);
    t=now+COleDateTimeSpan((double)(0xFFFFFFFFu-tk)/86400000.0);
    s=t.Format(fmt);
    printf("Next GetTickCount() Wrap to Zero DateTime: %s\n",s);
    return 0;
}
三岁、就很帅 2017-06-02
  • 打赏
  • 举报
回复
阿里云服务器用的淘宝假货
oyljerry 2017-06-02
  • 打赏
  • 举报
回复
可以看看系统日志syslog,或者找阿里云客服

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧