[C tossing series] uses C to call the DIOCP encoding client for communication, tossing the diocp

Source: Internet
Author: User

[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.

Related Article

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.