Cocos2d-x network programming connection php server Notes 1 learning cocos2d-x network programming is a very embarrassing problem, because the learners familiar with cocos2d-x are basically in game development a piece of client programming, to learn network programming, you must be involved in the server. But the question is, who will? When I leave the server, network programming is undoubtedly a mirage. Although there are examples of http transient connections and socket persistent connections on the official website, I don't know how to use them in actual problems. The tutorials on the Internet are also widely used. not some well-known reasons are that some of the source code cannot be run, and there are no articles to teach you how to implement them from scratch. We are unlikely to know much about the technologies used by mobile game servers. it is said that socket or Java are used for persistent connections, and phthon is used for short connections. of course, there are dedicated server frameworks like firefly, however, it is impossible for a game company to learn its learning cost in a short time. it is not very worthwhile to grasp it in a short time (generally, gaming companies want to earn fast money and cannot give you time to learn it ), we are learning cocos2d-x clients, not server programmers.
Now our goal is very clear, want to know how the cocos2d-x to interact with the server, at least how to initiate a response to the server, how to process the server returned data. We need to build the simplest server. Here we will implement the simplest user name login server authentication user name and password function. The server technology uses php + mysql technology. Why use php? Don't ask me why, because on the internet I only found a complete php Server Tutorial that can be run out of the box. in the past, our company used a server written in python to run stably, but the problem was, nobody taught me ......
Server construction:
It is also troublesome to build a php server from scratch. to download the php package and apache, to download and install the mysql database, there are also various configurations. I hate the environment configuration most, in particular, the server network environment is not familiar to us. if we don't have a good place, we will lose everything and no one will teach you how to use it. After half a day, the project manager will come and scold you for not making any progress. I ran into this miserable situation N times. Now, I am not so stupid. I don't want to study anything that is not within my expertise at 1.1 points because of my limited human resources. I want to build a php Server. I already have a ready-made tool on the Internet: phpStudy, integrated with apache + php + mysql + phpMyAdmin + ..., everything you want is integrated for you. all you have done is to double-click setup and perform the next step. you don't need to worry about any configuration. it will help you configure it and it is absolutely effective, it's awesome. For more information about the installation, see phpStudy installation.
It looks like this:
During the installation process, the directory of your website will be specified, that is, the storage location of the. php file you wrote. These. php files will all be server programs in the future. I put it under d:/phpWWW. The name is ugly, but it doesn't matter. There are port settings in the "other options menu". be careful not to conflict with other programs, otherwise, the server will not be connected, and the password settings of the mysql server will also be available. There is also the mySql manager, which can open a mySql front-end and create a database data table directly in it, which is very convenient. click other options to view the configuration at a glance. I will not talk about it here. please try it by yourself. You can see that both apache and mysql servers are in the starting state, and then try to enter the URL: http: // 127.0.0.1/phpinfo in your browser. php (based on the files in your website directory). If you can open it like the following, it means that your php + apache server has been set up !!
What editor should we use to write php files? When I used notepad too tired, I accidentally got a syntax error. we are not familiar with the php syntax. if I got a wrong syntax, it was a dead man. PhpDesigner 8 is recommended for use here. Baidu searches for a lot of PHP designer 8 registration codes, such as phpDesigner 8 cracking. it is said that PHP designer 8 can also be debugged. Please download and install it.
In the next section, we will learn how to write the php server program.