# 發生錯誤時的應對事項

## 解決因調試器暫停時服務器連接中斷的問題

爲了調試服務器或客戶端,正在調試的程序必然會因斷點設定等而暫時停止。

但是使用ProudNet時，在這些暫停中，數十秒後服務器和客戶端之間的連接就會斷開。 主機之間的連接異常斷開時, 一般都會立即檢測到, 但強制拔掉主機電源或通信線路等解除連接(hard disconnect)時, 不能立即檢測到。

然後每隔一段時間通過主機之間的交換乒乓分組檢測hard disconnect。 調試中的程序在數十秒內處於暫停狀態時，ProudNet也會識別爲hard disconnect，解除主機之間的連接。

爲了解決這一問題,可以使用<mark style="color:orange;">Proud.CNetServer.SetDefaultTimeoutTimeSec</mark>,將感知hard disconnect的時間設定得足夠長(例如一個小時)。

{% hint style="warning" %}
建議僅在調試時設置較長的 <mark style="color:orange;">Proud.CNetServer.SetDefaultTimeoutTimeSec</mark>。

如果將<mark style="color:orange;">SetDefaultTimeoutTimeSec</mark>設置在發佈給玩家的版本中，檢測hard disconnect玩家的斷開檢測可能需要太長的時間。

請注意，偶爾也會有惡意利用hard disconnect的遊戲玩家。
{% endhint %}

{% tabs %}
{% tab title="C++" %}

```cpp
// 例子

Proud::CNetServer* srv = ...;
#ifdef _DEBUG
srv->SetDefaultTimeoutTimeSec(60*10); // 10分鐘
#endif
```

{% endtab %}

{% tab title="C#" %}

```csharp
// 例子
Nettention.Proud.NetServer.SetDefaultTimeoutTimeMs


```

{% endtab %}
{% endtabs %}

## 如果發生建置錯誤

在進行<mark style="color:orange;">#include \<atlbase.h></mark>之前，請嘗試進行<mark style="color:orange;">include \<ProudNetServer.h></mark>或<mark style="color:orange;">include \<ProudNetClietn.h></mark>。 使用<mark style="color:orange;">stdafx.h</mark>時，建議在<mark style="color:orange;">stdafx.h</mark>的最前端加入<mark style="color:orange;">include \<atlbase.h></mark>。

使用<mark style="color:orange;">.Net Framework</mark>的程序有名爲System.String的符號，但ProudNet具有名爲<mark style="color:orange;">Proud.String</mark>的符號。 因此<mark style="color:orange;">.Net Framework</mark>混用時，String這個符號可能需要明示System或Proud中的一個名稱空間。

## P2P通信突然中斷，幾秒後重新恢復通信時

ProudNet在P2P通信過程中，如果P2P連接被切斷，感知需要數秒的時間。

如果判斷P2P連接在中間被阻塞，則將P2P連接切換到旁路模式。 這時無法發送的[**Reliable 信息**](/proudnet.cn/proudnet-note/dictionary.md#reliable)會同時發送和接收，[**Unreliable 信息**](/proudnet.cn/proudnet-note/dictionary.md#unreliable)會消失。

## 屏蔽 Assert 對話框

ProudNet在debug build內部運行過程中出現錯誤使用時，可顯示assert failure對話框。 如果想阻止這種情況發生， assert failure 必須設置成啓用其他操作， 而不是顯示對話框 。

也可以用自己製作的函數代替。 下面是例子。

{% tabs %}
{% tab title="C++" %}

```cpp
#include "stdafx.h"
#include <crtdbg.h>
 
int YourReportHook( int reportType, char *message, int *returnValue )
{
    return 1;
}
 
int _tmain(int argc, _TCHAR* argv[])
{
    _CrtSetReportHook(YourReportHook);
    assert(0); // now, this won't show you the message box.
    return 0;
}
```

{% endtab %}
{% endtabs %}

## CFastHeap或CLookasideAllocator相關例外時的解決方法

不僅是<mark style="color:orange;">Server, Client</mark>，ProudNet的許多內部客體也使用[**Fast Heap**](/proudnet.cn/proudnet-note/dictionary.md#fast-heap)，該實例包括[**C++ singleton**](/proudnet.cn/proudnet-note/dictionary.md#c-singleton)。\
如果將使用Fast Heap的<mark style="color:orange;">Server</mark>, <mark style="color:orange;">Client</mark>等實例作爲全局變量或全局變量的成員變量，則會發生例外。

使用 <mark style="color:orange;">C++ singleton</mark> 創建的實例應保留爲 <mark style="color:orange;">C++ singleton</mark> 而不是全局變量，因爲它確保 <mark style="color:orange;">WinMain()</mark> 或 <mark style="color:orange;">main()</mark> 在返回之前根據依賴對象關係被破壞。

## 最多不能同時在線人數超過5000人時

如果最多無法接收5000名同時在線者，請確認以下事項。

* [x] 服務器的CPU使用量是不是太高了？
* [x] 服務器的內存用量是不是太高了？
* [x] 服務器的Non paged pool使用量是不是太高了？
* [x] 服務器的網絡通信量是不是太高了？
* [x] <mark style="color:orange;">HKEY\_LOCAL\_MACHINE</mark>的<mark style="color:orange;">MaxUserPort(DWORD)</mark>值在5000以下嗎?

## 如果顯示找不到 ProudNetClientPlugin.dll 模塊

如果沒有安裝重新部署包，即使路徑中存在相應的庫，也會出現錯誤。

首次安裝ProudNet時，在最後階段可安裝重新部署包和CMake，安裝後ProudNet安裝路徑下游Bin文件夾中也有重新部署包，可安裝相應文件。

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.proudnet.com/proudnet.cn/proudnet-note/notes/how_to_solve_problems.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
