This article mainly introduces the network communication architecture of the Mobile Online Game client and the connection with the mobile network.
Agent 'K used to be a web engineer. I believe manyProgramPersonnel also started from Tomcat and Apache.
Basically, you do not need to care about network connections for Web applications. Web servers and browsers will handle this for you.
Of course, online games can also use HTTP connections, which requires that at least some of the functions of server programs operate in
On the web server (unless you embed something like jetty in the server program ).
The stateless feature of HTTP connections is also a problem. You need to find a way to let the server know which client initiated each connection.
Therefore, a better choice is socket connection.
Socket-connected data exchange is pure byte streams, so we must define a fixed data packet format,
To distinguish different logical data packets. There is an open-source network communication framework on the server: Mina (Java ).
It provides some extensible custom interfaces for logical data packets. A simple example is:
Each packet starts with an int to indicate the length of the Data Part of the packet. What then?
You know what to do ~
Do you still see any frameworks available on the client? Do it yourself and stir-fried dishes to taste them,
A self-built framework has a sense of accomplishment ~
--MARK: This is related to the proxy server.--
The mobile Internet is connected only to China Mobile. (I have to say that China Mobile literally occupies the mobile Internet keyword,
So the illusion is that "mobile" is China Mobile. But other telecom providers, well, "Telecom" has also been occupied.
It really lags far behind China Mobile, at least on mobile game access .) Currently, most mobile online games are connected to cmwap first.
You may ask, if our server is placed in an IDC with an independent IP address, will not be accessible on any mobile phone that can access the Internet? Otherwise, this is a historical issue.
Previously, mobile phones used to access the Internet only through WAP and GPRS. The former requires China Mobile to open a specific interface (socket) for access, which is useful in terms of access speed and traffic saving.
Although such a specific interface may or will exit the stage of history, it is still rooted in depth.
Well, I have heard that my children's shoes may be impatient. Let's talk about socket.
Simple ~ It is a fixed IP address and port. After the client establishes a connection with it, it immediately sends the specified recognition byte, And it will establish a connection to our server, after which all the data will be forwarded.
Over. Note that our servers are generally stored in the data center of the mobile ISP. The specified recognition byte is forwarded to our server as is,
This feature breaks the Client Communication Data Structure mentioned above. The server needs to initialize the connection to eliminate the impact of these bytes.
Well, *** something wrong in that place. Some great gods may be laughing. Don't spray it. please correct me and share it.
= Cut =
After checking it again, the client needs a separate thread to handle network communication. It is one of the only threads on the client. What are other threads? Bury a foreshadowing. Hey.