[C tossing series] uses C to call the DIOCP encoding client for communication, tossing the diocp
A friend said a few days ago that their company is engaged in mobile games. The server uses DIOCP3 as the file server, and the client uses cocos-x, which always fails in debugging communication with diocp!
So I downloaded a Codeblocks, and after several hours, I finally tried it out. I recorded some of it for future reference.
1. When using socket functions in windows, you need to set the project options or tool compilation options.
[Project-> build options]-> [linker settings] or [setting]-> [complier]-> Linker settings] add
F: \ Tools \ C \ CodeBlocks \ MinGW \ lib \ *. a to [link libraries]
Otherwise, a compilation error occurs.
Undefined reference to 'wsastartup @ 8'
2. About extern and static in c
There are many explanations on Baidu,
Extern indicates that the modified function or variable is referenced from other files. (Extern tells the compiler that the variable or function has been defined in other files)
Static indicates that modified functions or variables can only be used in this file. Static can also modify the local variable, indicating that the local variable is unavailable after exiting the function, but when it enters the function again, the variable will save the previous value.
Below is the debugging
The preceding description communicates with the server. The server receives a specific encoding format (Flag + CheckValue + datalen + data)
After the message is sent, the server returns the code as is.
Summary:
When using a different language, you need to write more code. Only when writing can you encounter problems, solve problems, and accumulate experiences. There are ideas and ideas, and the rest is just getting stuck.