Online online game development experience (server side) (2)

xiaoxiao2021-03-06  39

Bromon Original, please respect copyright, communication protocol

This project does not have a complex communication directive, the number of commands is limited, but there is still a key issue to pay attention: traffic. To minimize traffic, we use bytes instead of strings to save system instructions, so that traffic is reduced by half, such as using one byte to save a poke card, byte high expression color, byte low represents numbers, if 0 represents black peaches, then black peach three should be 0x03, this requires reincarnation operation:

INT m = 0;

INT n = 3;

BYTE CARD = (BYTE) (M) << 4) | ((byte) n; // m left four digits, then with N left or operation

In the game, you need to pass the user's integral. This is a big integer that uses four bytes to save comparison insurance, convert the integer to the four bytes, as follows:

Package Org.bromon.games.al; public static byte [] translatelong (long mark)

{

Byte [] b = new byte [4];

For (int i = 0; i <4; i )

{

B [I] = (Byte) (Mark >>> (24 - i * 8));

}

Return B;

}

The operation of the four bytes turns back is as follows:

Package org.bromon.games.al;

Public Static Long TranslateByte (Byte [] B)

{

INT MASK = 0xFF;

INT TEMP = 0;

INT RES = 0;

For (int i = 0; i <4; i )

{

RES << = 8;

Temp = b [i] & mask;

RES | = TEMP;

}

Return res;

Next: About Database Connection Pool

转载请注明原文地址:https://www.9cbs.com/read-68907.html

New Post(0)