"Network game server Programming"

Source: Internet
Author: User
Tags epoll socket error

This book is written by a Korean, the book is very old, 2006 published, there is no update, only a little reference.
1. OSI Seven layer: Physical layer, Data link layer, network layer, transport layer, Session layer, presentation layer, application layer.
2. Ah,ph,sh,th,nh,dh; App header,,, each layer has a Baotou (application layer header, transmission layer Baotou, etc.);
TCP/IP protocol cluster, 4 layer, physical layer, network layer, Transport layer, application layer;
Ethernet Header-ip Header-TCP header-Application layer data-user data.
The header usually contains: Destination address, source address, frame type and other information; (Serial number, confirmation number, checksum)
3.IP & Mask is equal in one network.
4. Socket socket. Returns a file descriptor, an integer data.
SetSockOpt ();
Blocking and non-blocking: non-blocking does not wait for the result when calling Send/recv, executes the following statement directly; blocking waits.
The default is blocking mode. Blocking requires setting properties (LINUX:FCNTL); Most applications use non-blocking mode.
Non-blocking programming is more difficult, but highly efficient and flexible.
Blocking is generally done with multithreading, and multiple socket links are not a good choice, should be used SELECT,POLL,EPOLL,IOCP model.
5. The sending and receiving data is temporarily present in the system buffer queue. Recv queue.
Windows Socket Error: operation on socket cannot be performed due to insufficient system buffer space or queue is full (10055), on API Connect
Workaround:
1, restart the computer, the simplest way.
2. The virtual memory is too small or the C disk is full. If this is the case, increase the amount of virtual memory and make sure there is plenty of room for the C drive.
The packet per send cannot be too large.
int recvdata (int sock,char *read_buf,int len);
6. Select: multiple input and output functions.
SetSockOpt: Change the socket default property value.
7.winsock:
Wsastartup,wsacleanup. (Sock DLL)
Blocking,nonblocking: Always waiting for results. Ioctlsocket (): nonblocking
Socket mode (BLOCK,NONBLOCK) and socket I/O model
8. The Select model is the most common I/O model.
The WSAAsyncSelect and WSAEventSelect functions automatically set a socket to nonblocking mode
The Windows operating system provides selection (select), asynchronous Selection (WSAAsyncSelect), event selection (WSAEventSelect), overlapped I/O (Overlapped I/O), and completion ports (completion port) A total of five I/O models.
Millisecond:ms
Microsecond:us
Timeval:select function to specify the maximum time the function can take to complete.
9.

fd_clr (S, *set ) removes the  descriptor S from  set . Fd_isset (S, *set ) nonzero if  S is a  member of  the  set . Otherwise, zero . Fd_set (S, *set ) Adds descriptor S to  set . Fd_zero (*set ) initializes the  set  to  the  null  set . 

Focus on business logic
10. When it comes to handling large numbers of connections, how inefficient is the Select (<=64 connection). We should swap with IOCP (Windows), Kqueue (FreeBSD), or Epoll (Linux).
7x24 process Restart.
What is the role of select?
His role is to prevent the locking of the socket in blocking mode and to avoid repeated checks of wsaewouldblock errors in non-blocking sockets.
11.tv.tv_sec = 2;//Here we are going to let select wait two seconds to return, avoid being locked out, and avoid returning immediately
Libevent,boost.asio (Windows:iocp,linux:epoll),
12. Register server-game server 1-game server 2-game server 3 ... -Database server.
13. Development of communication protocols
protocol header, data length, command number, data, checksum, data tail
Communication: Protobuf

Game server programming and the normal program is no different, his characteristics are:
1. No GUI interface, just pure data communication and processing.
2. Using socket communication, it is necessary to use the high concurrency IO model, can use Libevent/libev/boost::asio and other mature network library, can also be developed by themselves.
3. Need database, need to pay attention to the data query Access optimization.
4. Generally need log access operation information, abnormal information;
5. May need to protobuf and other software for communication protocol packaging;

Personal opinion ...

"Network game server Programming"

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.