用的是阿里云的服務器,這個問題我不是第一次發現了,這個周期長的時候幾個月一次,短的話也是最少一個月,不單單是我自己的服務端,微軟的netsh,也是長時間后會失效,有人遇到過這種問題嗎?
uj5u.com熱心網友回復:
阿里云服務器用的淘寶假貨
uj5u.com熱心網友回復:
可以看看系統日志syslog,或者找阿里云客服uj5u.com熱心網友回復:
正常來講,不會出現這種情況。如果出現了這種情況,建議寫個超時啟機制。
uj5u.com熱心網友回復:
十有八九和這個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;
}
uj5u.com熱心網友回復:
會不會是你的服務器端軟體, 采用的是老的xp時期的APM廣播訊息來阻止服務器進入休眠狀態?這樣你服務器端如果一直繁忙那么沒問題,但是如果期間有一段時間無連接
服務器會被強制進入休眠狀態的
uj5u.com熱心網友回復:
在windows下,Listen函式會在網線拔掉(網路不可用)后,失效。uj5u.com熱心網友回復:
GetTickCount別人試 貌似40多天就溢位了。很大的數 溢位成最小,程式邏輯就跪了。要么使用GetTickCount64 范圍增大,時間更長。要么用別的api
uj5u.com熱心網友回復:
代碼添加判斷如果失效,等條件允許的時候,重新listen
uj5u.com熱心網友回復:
你確定會這樣?
我怎么沒測驗到有這樣的情況發生呢?
只要bind null也就是本機所有ip地址
即使拔掉網線,或者干脆換ip
都不會有問題,新的ip設定后同樣會自動系結
除非你系結了指定的ip地址,然后這個ip被換掉才會出現失敗
問題是服務器端,沒有什么人會系結一個指定IP的吧,一般都是全系結
uj5u.com熱心網友回復:

解決辦法
1.寫個客戶端監控,比如每分鐘連一次,如果都連不上,則重啟服務端。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/82924.html
標籤:網絡編程
