Reconnect hrc+ Smartfoxserver 2X

Source: Internet
Author: User
Tags socket

Reconnect HRC +

Since Smartfoxserver 2X version 2.5 (and later) introduced an improved version of the highly resilient connection system (HRC +), players can rejoin the server after a sudden disconnection without losing their current state.

In this article, we'll discuss the ways in which HRC + can save a lot of development work, how it's technically done, and how to configure and test.
Why did I disconnect the connection.

Accidental disconnection is very rare when developing and testing on-premises networks, but when we finally surf the Internet, there may be several pranks that might affect the game's connection.

The main reason for the connection to be discarded without notice is traffic congestion. Player connections typically reach their destination through dozens of network nodes, and each of these links can be a potential point of failure. In fact, if any of these routers and gateways are overwhelmed by traffic, they may be slow to respond, forced to drop packets or resets, causing stall and eventual disconnection.

If we add a hybrid WiFi and a mobile connection, the scene becomes more delicate because the drop in signal strength can cause a sudden disconnection with the game server.

All of these situations are primarily low-level in the TCP stack of the operating system, and the TCP stack dispatches the response that other programs can make at the application level. Smartfoxserver 2X In these respects is no exception, it depends to a large extent on those low-level notifications.

Later in this article, we will see what might happen if certain events are not resolved in a timely manner.
»HRC + Rescue

HRC + is a unique feature of the Smartfoxserver 2X that helps build a more powerful multi-user game that allows players to return to the game transparently without losing their status.

The following figure shows what happens when the player suddenly disconnects from the server:

Starting from the left, we have three users connected to SFS2X, all players playing together in the same area of the player a,b,c. Suddenly User B loses connection, the Player object on the server is frozen, and all messages sent to him are stored in the queue.

Meanwhile, the client API is trying to establish a new connection while the other players can continue their game knowing that User B is trying to jump back.

On the right side of the graph, Player B is finally reconnected. The new session is linked to the old player object, the client is updated to all queued messages, and the other player is notified that B has returned. The exciting part is that at all these stages, the game flow is uninterrupted and all the complexities of reconnecting are hidden from the developer.
» Errors may occur

Not all disconnected connections are equal. Intermittent may exist for some time in a few cases and cannot trigger a re-connected system.

We dedicate the entire part of the document to the problem of ghost connections, which is how we invoke the "semi-closed" TCP connection. Without too much detail, the TCP protocol uses multiple message exchanges to disconnect clients and servers. This interchange cannot be completed when the network is suddenly unavailable, and the TCP connection can remain in a "wait" state for a period of time.

A typical cause of this is a sudden loss of the signal from the computer pulling the network cable or the WiFi interface or the mobile connection. In all these cases, a ghost connection may eventually occur, and the TCP connection is still waiting for the shutdown operation to complete.

Why HRC + features are so relevant. This is critical because TCP sockets in this state will not notify any disconnected events at the application level, so smartfoxserver will not be aware of this new condition. Eventually, the TCP timeout or Smartfox idle socket timeout will be triggered (depending on the earlier boot), and the connection event will be disconnected.
Do not unplug the power
» Correct Disconnect test method

Reverse unplugging the network cable or turning off the WiFi connection does not result in a sudden disconnection that can be used for testing.

In fact, you can use the Netstat utility (available on Windows,mac and Linux) to monitor your computer's connection before and after unplugging the cable, and you will be surprised to see that there are no changes.

Important: Do not try to reconnect the system by unplugging the ethernet cable or by turning off the WiFi connection. None of the two operations terminates your current socket connection, so the disconnect event will never be triggered.

Instead, follow the instructions provided in the article entitled "Connection Phase", which we link in the following section.
» Further Reading

For more information about how to configure and test HRC +, see the connection phase in the "Development Fundamentals" section.
to learn more about how TCP/IP handles disconnection, you can read this external article

Translated from Http://docs2x.smartfoxserver.com/GettingStarted/reconnection-hrc-plus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.