> For the complete documentation index, see [llms.txt](https://docs.proudnet.com/proudnet.eng/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.proudnet.com/proudnet.eng/proudnet-note/notes/communcation_lan.md).

# \[Version 1.6] Server-to-Server LAN Communicator

{% hint style="danger" %}
LanServer, LanClient have been retired since version 1.7.\ <mark style="color:orange;">NetServer</mark>, <mark style="color:orange;">NetClient</mark> take over the roles of LanServer, LanClient.<br>

**Reference**\
[**Migration from ProudNet 1.6 Lan Module to 1.7 Net Module**](https://docs.proudnet.com/proudnet.eng/proudnet-note/notes/pages/YpGn7LMFpdoyJAHkIMhf#migration-from-proudnet-1.6-lan-module-to-1.7-net-module)
{% endhint %}

## Features of LAN communicators

The difference between a ProudNet server and a LAN communicator between the network and the server is as follows.

<table data-full-width="false"><thead><tr><th width="251">Sections</th><th width="261">ProudNet Server and Network</th><th>Server-to-Server LAN Communicator</th></tr></thead><tbody><tr><td>Key uses</td><td>Common user applications communicate with the server</td><td>Communication between servers in a distributed server structure</td></tr><tr><td>NNAT Device Transmission</td><td>YES</td><td>NO</td></tr><tr><td>P2P relay(relay)</td><td>YES</td><td>NO</td></tr><tr><td>Client-to-server communication protocols</td><td>TCP and UDP</td><td>TCP</td></tr><tr><td>P2P communication protocols</td><td>(Reliable) UDP</td><td>TCP</td></tr><tr><td>Client's callback method</td><td>Poll (Callback from <mark style="color:orange;">Proud.CNetClient.FrameMove</mark>)</td><td>Callbacks from a thread pool</td></tr></tbody></table>

<mark style="color:orange;">lan\_main</mark> provides high-speed communication between hosts as follows.

> * Because it only uses TCP, it uses the server hardware's communication acceleration (TCP Offload Engine).
> * Unlike <mark style="color:orange;">Client</mark>, events and incoming messages are callbacked on a thread pool.\
>   Of course, the server side also fires callbacks from the thread pool.

## Using LAN communicators

The usage of the ProudNet server and the network and LAN communicators is almost identical.

The following are API differences.

<table><thead><tr><th width="221">Sections</th><th width="261">ProudNet Server and Network</th><th>Server-to-Server LAN Communicator</th></tr></thead><tbody><tr><td>Server</td><td>Proud.CNetServer</td><td>Proud.CLanServer</td></tr><tr><td>Client</td><td>Proud.CNetClient</td><td>Proud.CLanClient</td></tr><tr><td>Server event handler</td><td>Proud.INetServerEvent</td><td>Proud.ILanServerEvent</td></tr><tr><td>Client event handler</td><td>Proud.INetClientEvent</td><td>Proud.ILanClientEvent</td></tr><tr><td>Message pool method</td><td>Proud.CNetClient.FrameMove</td><td>None (callback in thread pool)</td></tr></tbody></table>

## P2P communication on LAN communicators

For P2P communication between <mark style="color:orange;">Proud.CLanClient</mark> hosts, the TCP protocol is used.

When P2P messaging is initiated by <mark style="color:orange;">Proud.CLanServer.CreateP2PGroup</mark>, for example, as soon as P2P communication between hosts is established, the message you want to send is stored in each host's local queue until the TCP connection between peers is established. The stored messages will start sending immediately as soon as the TCP connection is established.

As soon as a TCP connection is established, <mark style="color:orange;">Proud.ILanClientEvent.OnP2PConnectionEstablished</mark> and <mark style="color:orange;">Proud.ILanServerEvent.OnP2PConnectionEstablished</mark> are called.

On the other hand, when the TCP connection is disconnected, <mark style="color:orange;">Proud.ILanClientEvent.OnP2PDisconnected</mark> and <mark style="color:orange;">Proud.ILanServerEvent.OnP2PDisconnected</mark> are called.

<mark style="color:orange;">Proud.ILanClientEvent.OnGroupP2PConnectionComplete</mark> and <mark style="color:orange;">Proud.ILanServerEvent.OnGroupP2PConnectionComplete</mark> are called when all members in the P2P group have established a TCP connection.

## Thread pool on LAN communicators

<mark style="color:orange;">Proud.CLanClient</mark> does not have a corresponding function for <mark style="color:orange;">Proud.CNetClient.FrameMove</mark> because event callbacks and RMI callbacks occur on threads in the thread pool, which is prepared by <mark style="color:orange;">Proud.CLanClient</mark>.

<mark style="color:orange;">Proud.CLanConnectionParam.m\_netWorkerThreadCount</mark> allows you to specify the number of threads in the thread pool that the client should have.

<br>

## Handling disconnections from LAN clients

Because the LAN client creates a <mark style="color:orange;">user worker thread pool</mark> during the connection process (<mark style="color:orange;">CLanClient.Connect</mark>) and removes that pool during the disconnection process (<mark style="color:orange;">CLanClient.Disconnect</mark>), the LAN client cannot issue disconnect or connect commands on <mark style="color:orange;">user worker thread</mark>.

If implemented, <mark style="color:orange;">Proud.Exception</mark> will occur.

<br>

## RMI on LAN communicators

This is the same as using [**RMI**](/proudnet.eng/proudnet/using_pn/rmi.md).

## Synchronizing time in server-to-server communication

It is the same as [**how to get server time from the client**](/proudnet.eng/proudnet/using_pn/server_client/using_client.md#getting-the-servers-time).

## Migration from ProudNet 1.6 Lan Module to 1.7 Net Module

### - Precautions when changing from 1.6 Lan Module to 1.7 Net Module

Requires a thread model specification when calling <mark style="color:orange;">NetClient.Connect()</mark>.

When calling, you must put a parameter in the <mark style="color:orange;">m\_userWorkerThreadModel</mark> to allow the user callback to be received by multiple threads.

Or, attach the thread pool object you created to the <mark style="color:orange;">m\_externalUserWorkerThreadPool</mark> parameter.

This thread pool has multiple threads.

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

```cpp
void CFarmClient::Connect()
{
    CNetConnectionParam p1;
    p1.m_protocolVersion = CFarmSettings::GetSharedPtr()->GetFarmVersion();
    p1.m_serverIP = L"localhost";
    p1.m_serverPort = CFarmSettings::GetSharedPtr()->GetFarmServerPort();
    p1.m_timerCallbackIntervalMs = 1000;
 
    // To handle event processing for m_lanClient in the user worker thread pool. 
    // And to avoid having to call FrameMove.
    p1.m_userWorkerThreadModel = ThreadModel_MultiThreaded;
 
    // The outerror will only point to the ErrorInfo allocated on the heap when an error occurs.
    // If you want to use an outerror after the Connect call, you must check if it is NULL before using it.
    ErrorInfoPtr outerror;
    m_lanClient->Connect(p1, outerror);
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Communication between servers has changed from traditional TCP communication to UDP-based communication, which requires firewall work around UDP ports.
{% endhint %}

### - How to change from 1.6 Lan Module to 1.7 Net Module

> 1. **1.7 Prepare the library.**\
>    The library is located in <mark style="color:orange;">\<install folder>/ProudNet/lib/</mark>.
> 2. **Change the function name from Lan to Net.**\
>    This includes all classes, functions, and methods. Most are a 1:1 match, so you shouldn't have to make any major changes.

### - Example of migrating a 1.6 Sample/SimpleLan example to 1.7

> * **LanCommon** → <mark style="color:orange;">NetCommon</mark>
> * **UUID** → <mark style="color:orange;">PNGUID</mark>
> * **Guid::From(guid)** → <mark style="color:orange;">Guid(guid)</mark>

<figure><img src="/files/0FDtkrjjjzSyV2tVsDmr" alt=""><figcaption><p>LanToNet_Common_01</p></figcaption></figure>

> * **LanServer** → <mark style="color:orange;">NetServer</mark>
> * **CLanServerEventSink** → <mark style="color:orange;">CNetServerEventSink</mark>
> * **OVERRIDE** → <mark style="color:orange;">PN\_OVERRID</mark>
> * **CLanServer** → <mark style="color:orange;">CNetServer</mark>
> * **CStartLanServerParameter** → <mark style="color:orange;">StartServerParameter</mark>
> * **p1.m\_tcpPort = g\_ServerPort** → <mark style="color:orange;">p1.m\_tcpPort .Add(g\_ServerPort)</mark>

<figure><img src="/files/WyX8y951T2KmYhRyW0FR" alt=""><figcaption></figcaption></figure>

> * **LanClient** → <mark style="color:orange;">NetClient</mark>
> * **CLanClient** → <mark style="color:orange;">CNetClient</mark>
> * **ILanClientEvent** → <mark style="color:orange;">INetClientEvent</mark>
> * **OVERRIDE** → <mark style="color:orange;">PN\_OVERRID</mark>
> * **CLanClient::Create()** → <mark style="color:orange;">CNetClient::Create()</mark>
> * **CLanConnectionParam** → <mark style="color:orange;">CNetConnectionParam</mark>
> * **ProudNetServer.h** → <mark style="color:orange;">ProudNetClient.h</mark>

<figure><img src="/files/nMWT6Skpfm4xcJkhLRJ2" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.eng/proudnet-note/notes/communcation_lan.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.
