The BOOL cemuleapp::initinstance () function has 672 rows (VERIFY (M_htimer =:: SetTimer (null, NULL, Startuptimer))!= NULL);
Start a timer in the execution function of the timer (void CALLBACK Cemuledlg::startuptimer (HWND/*hwnd*/, UINT/*uimsg*/, UINT/*idevent*/, DWORD/*dwti me*/))
814 rows of Theapp.emuledlg->onbnclickedbutton2 (); Connect to emule server
Cserversocket is a client-server session class (or server Class), which connects to a specific server, handling all things related to the server, such as (specific) data, data collection, connection arrival, etc.
Handle various situations in the incoming function (void cserversocket::onconnect (int nerrorcode)) (whether to continue trying to connect)
The virtual void onreceive (int nerrorcode) function processes the packets received.
Because the connection is more complex, a class cserverconnect is specifically encapsulated to connect to the server. Cserverconnect drives the connection to multiple servers, stops the connection attempt, disconnects, processes the specific information after the connection (if the connection is correct, sends the login message, the error is reconnected) timeout detection, etc.
This two-class coupling is strong, so the analysis is more troublesome. The better case is that only the coupling relationship is exported, and one class references another class
Some functions that are related to two classes can be separated to form a new class, so the responsibility is relatively singular
Exception: maintains a state machine (connecting and connected two states) for the Cserverconnect class
There are different treatments for the two situations, for example, the customer class starts a new connection multiple times for the connecting state
For the Cserversocket class, there are different situations after the connection arrives. If normal, send a login message and turn off all connections to other servers
If it fails, start a timer cserverconnect start a new connection
Trying to connect to a server
First step:
Connecttoanyserver (UINT startAt, bool Priosort, BOOL Isauto, bool bnocrypt);
In this function, first stop all connected and connected
Handle if there is a static server
Listening socket start up listening
Tryanotherconnectionrequest ();
Start connection
Normally, start in the Tryanotherconnectionrequest function.
Connecttoserver (Next_server, True,!m_btryobfuscated);
This function actually implements a connection to the server, if the connection is
Cuploadqueue:: 965 lines of the Uploadtimer () function
if (theapp.serverconnect->isconnecting ())//If you are connecting, check for timeout
Theapp.serverconnect->checkfortimeout (); Check whether the connection timed out after one second
Check to see if the connection timed out
Send login If you are connected or the server waits for login information
The client waits for a connection event to occur when the connection is being connected
void Cserversocket::onconnect (int nerrorcode)
Handle various connection events in this function, if normal, then restart connection with other server if the log message is not normal
Exception handling function
void cserverconnect::connectionfailed (cserversocket* sender)
The donkey connects the server the process writes more exquisite, mainly has two class cserversocket, Cserverconnect to complete the server connection and the communication
The BOOL cemuleapp::initinstance () function has 672 rows (VERIFY (M_htimer =:: SetTimer (null, NULL, Startuptimer))!= NULL);
Start a timer in the execution function of the timer (void CALLBACK Cemuledlg::startuptimer (HWND/*hwnd*/, UINT/*uimsg*/, UINT/*idevent*/, DWORD/*dwti me*/))
814 rows of Theapp.emuledlg->onbnclickedbutton2 (); Connect to emule server
Landing server
The above basic completion of the server connection process