Git Product home page Git Product logo

asio_kcp's Introduction

asio_kcp - a fast and reliable udp framework.

This framework will be the fastest protocal for pvp game.

kcp - a A Fast and Reliable ARQ Protocol (Can use with UDP)

This project wrap kcp by boost asio. Making it easy to use.

Feature

  • Using in realtime pvp game that need miniest network delay. For example, the multiplayer first person shooting game.
  • Reliable UDP protocal.
  • Minimize delay. And the worst delay should be good. 3 or more times better than enet when worst network lag happen.
  • Has good performace in wifi and phone network(3G, 4G).
  • Extra using 20% ~ 50% network flow for speed improvement.

Bench mark

worst network lag happen:
asio: 10:51.21
291  295   269   268   231   195   249   230   225   204

enet: 10:51.21
1563   1520    1470    1482    1438    1454    1412    1637    1588    1540
You can see the bench mark test result at here
Or you can see the bench mark detail log at bench_mark folder.

client_lib

Feature:

  • Do not using boost. And do not using feature of c++11
  • It's implement by original thread and socket.
  • client_lib_usage

Recommend: use Dockerfile to compiling the server and client.


### Or create compiling env yourself
* I using gcc 4.8 * Other version of gcc that support c++11 should be OK. You can compile asio_kcp as verifying.
  • I using boost 1.58

    • Other version of boost should be OK. You can compile asio_kcp as verifying.
  • Build g2log

    • download g2log from official website
      • or using the package in third_party folder.
    • cope g2log folder to third_party folder
    • $ cd third_party/g2log/ && mkdir build && cd build && cmake .. && make
  • Build muduo

    • $ cd third_party/
    • $ git clone https://github.com/chenshuo/muduo.git
      • or using the package in third_party folder. third_party folder.
    • $ cd muduo
    • compile on OSX: $ patch -p1 < MacOSX.diff
      • edit muduo/CMakeLists.txt.
        • find set(CXX_FLAGS then add 2 new line:
          • -D__GXX_EXPERIMENTAL_CXX0X__
          • -std=c++11
        • comment -march=native
        • comment set(CMAKE_CXX_COMPILER "clang++")
        • comment -Werror
        • uncomment -DMUDUO_STD_STRING
    • compile on linux:
      • edit muduo/CMakeLists.txt.
        • find set(CXX_FLAGS then add 2 new line:
          • -D__GXX_EXPERIMENTAL_CXX0X__
          • -std=c++11
        • uncomment -DMUDUO_STD_STRING
        • comment -Werror
    • modify muduo/base/LogStream.h kSmallBuffer = 4000 -> kSmallBuffer = 4000*4
    • adding VERBOSE=1 to "make" in muduo/build.sh will show detail of compiling.
    • $ CC=gcc CXX=g++ BUILD_DIR=./build BUILD_TYPE=release BUILD_NO_EXAMPLES=1 . ./build.sh
  • modify the BOOST_LIB_PATH and BOOST_INC_PATH in allmake.sh

  • do compiling at project root folder: $ . allmake.sh

The third_party folder should like below,

▾ third_party/
  ▾ g2log/
    ▸ build/
    ▸ src/
    ▸ test_example/
    ▸ test_performance/
    ▸ test_unit/
      CMakeLists.txt
  ▸ muduo/

Compile unit test

  • download gtest from website
    • or just use the package in third_party folder.
  • unpack the gtest-1.7.0.zip. coping gtest-1.7.0 folder to asio_kcp/third_party/
  • $ cd gtest-1.7.0 && ./configure && make
  • download googlemock from https://googlemock.googlecode.com/files/gmock-1.7.0.zip
    • or just use the package in third_party folder.
  • unpack the gmock-1.7.0.zip. coping gmock-1.7.0 folder to asio_kcp/third_party/
  • $ cd gmock-1.7.0 && ./configure && make
  • back to asio_kcp folder then $ . utest_make.sh
  • $ ./asio_kcp_utest/asio_kcp_utest

The third_party folder should like below,

▾ third_party/
  ▸ g2log/
  ▸ gmock-1.7.0/
  ▸ gtest-1.7.0/
  ▸ muduo/

Run example test

filter the verbose log from asio timer
./server/server 0.0.0.0 12345 2>&1 | grep --line-buffered -v -e deadline_timer -e "ec=system:0$" -e "|$" >>bserver.txt
filter all asio log
./client_with_asio/client_with_asio 23425 127.0.0.1 12345 500 2>/dev/null

run bench mark test of kcp.

  • Server on your server
git checkout kcp_bench_mark_test
read the readme.md in this branch. and do compiling thing.
then run server on your server:
  ./server/server 0.0.0.0 12345 2>&1 | grep --line-buffered -v -e deadline_timer -e "ec=system:0$" -e "|$" >>bserver.txt
  • run client on your client computer
git checkout kcp_bench_mark_test
read the readme.md in this branch. and do compiling thing.
./client_with_asio/client_with_asio 23445 120.26.200.117 12345 500 2>/dev/null
# Note: changing the ip and port to your server which is running the asio_kcp_server

how to test 3G/4G

  • if you want to test the 3G/4G. you can share the wifi on your phone by using wiless AP. Making your client computer connect to this wifi.
  • run client on your client computer (Note: changing the ip and port to your server)

Centos 6.5 install help:

  • $ yum -y install python-devel
  • $ tar jxvf boost_1_58_0.tar.bz2
  • $ cd boost_1_58_0
  • $ ./bootstrap.sh
  • $ sudo ./b2 install --build-type=complete --layout=tagged

error when running server

/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found
  • strings /usr/lib64/libstdc++.so.6 | grep GLIBC // check the GLIBCXX_3.4.15. It is not in it.
  • sudo find / -name "libstdc++.so*" 2>/dev/null // find the latest libstdc++.so It should be /usr/local/lib64/libstdc++.so.6.0.18
  • sudo rm /usr/lib64/libstdc++.so.6
  • sudo cp /usr/local/lib64/libstdc++.so.6.0.18 /usr/lib64/
  • sudo ln -s /usr/lib64/libstdc++.so.6.0.18 /usr/lib64/libstdc++.so.6
  • sudo vim /etc/ld.so.conf // add a new line: /usr/lib64
  • sudo ldconfig // all ok

OSX install help

gcc 4.8

  • install port if do not have one: https://www.macports.org/install.php
  • port search gcc # show gcc version
  • sudo /opt/local/bin/port install gcc48
  • sudo /opt/local/bin/port select --set gcc mp-gcc48
  • last step, close old shell, open a new shell.

boost 1.58

asio_kcp's People

Contributors

libinzhangyuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asio_kcp's Issues

请求消息内容过大时会被截断为固定352256大小

server的event_callback取到的消息大小为固定的352256
void GWServer::event_callback(kcp_conv_t conv, kcp_svr::eEventType event_type, std::shared_ptrstd::string msg)
{
AK_WARNING_LOG << "cannot parse request: " << msg->size() << std::endl;
}

client:
asio_kcp::kcp_client_wrap net;
flatbuffers::FlatBufferBuilder builderOut;
builderOut.PushBytes(reinterpret_cast<unsigned char*>(const_cast<char*>(msg.data())), msg.size());// msg size: 10M
net.send_msg(msg);

connect() and close()

I think you should implement connect() and close(), just like syn and fin.
The connect() send the SYN and wait SYN/ACK to make sure the server exist.
And the close() send the FIN and wait FIN/ACK.
If the server receive a packet which does not match the conv, a RST packet should send out.

启动即崩溃:/lib64/libpthread.so.0

[game@VM_109_84_centos server]$ ./server 0.0.0.0 12345
FILE ERROR: could not open log file:[/var/log/asio_kcp_log/server.g2log.20180209-114600.log]
std::ios_base state = 4
Cannot write logfile to location, attempting current directory

***** FATAL TRIGGER RECEIVED *******
Received fatal signal: SIGSEGV(11)
PID: 15238
stack dump [1] /lib64/libpthread.so.0+0xf370 [0x7f36bbd7e370]
stack dump [2] /lib64/libc.so.6setbuffer+0x7 [0x7f36bba1b597]
stack dump [3] ./server() [0x43e0c0]
stack dump [4] ./server() [0x43e1f6]
stack dump [5] ./server() [0x41901e]
stack dump [6] /lib64/libc.so.6__libc_start_main+0xf5 [0x7f36bb9cfb35]
stack dump [7] ./server() [0x4074b4]

***** RETHROWING SIGNAL SIGSEGV(11)

g2log exiting after receiving fatal event
Log file at: [./server.g2log.20180209-114600.log]

Exiting - FATAL SIGNAL: 11 段错误

系统版本
[game@VM_109_84_centos server]$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
GCC/G++版本
[game@VM_109_84_centos server]$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11)

谢谢作者。

Memory leak

Hi, i have ran the asio_kcp in centos. But i found there is memory leak from server_lib. Do you know what may cause this... thanks!


[root@ ~]# free
total used free shared buffers cached
Mem: 1922244 237748 1684496 0 12260 155564
-/+ buffers/cache: 69924 1852320
Swap: 0 0 0
[root@ ~]# free
total used free shared buffers cached
Mem: 1922244 238104 1684140 0 12268 155972
-/+ buffers/cache: 69864 1852380
Swap: 0 0 0
[root@ ~]# free
total used free shared buffers cached
Mem: 1922244 250132 1672112 0 12532 167364
-/+ buffers/cache: 70236 1852008
Swap: 0 0 0

quick_make failed

linux@linux-desktop:~/github/libinzhangyuan/asio_kcp$ sh quick_make.sh

[-------------------------------]
   essential
[-------------------------------]
g++  -std=c++11 -Wall -D _UTEST_ -g3 -c _src/check_function.cpp -o _src/check_function.o
g++  -std=c++11 -Wall -D _UTEST_ -g3 -c _src/utility/strutil.cpp -o _src/utility/strutil.o
ar -cr essential.a ./_src/check_function.o ./_src/utility/strutil.o


[-------------------------------]
   server_lib
[-------------------------------]
make: Nothing to be done for 'all'.


[-------------------------------]
   server
[-------------------------------]
g++  -std=c++11 -Wall -I /usr/include -I ../third_party/muduo -I ../server_lib -I ../third_party/g2log/src -g3 -D BOOST_ASIO_ENABLE_HANDLER_TRACKING -D BOOST_ASIO_ENABLE_BUFFER_DEBUGGING -D MUDUO_STD_STRING -D __GXX_EXPERIMENTAL_CXX0X__ -D AK_ENABLE_UDP_PACKET_LOG -c main.cpp -o main.o
main.cpp:18:8: error: ‘scoped_ptr’ in namespace ‘boost’ does not name a template type
 boost::scoped_ptr<muduo::LogFile> g_logFile;
        ^~~~~~~~~~
main.cpp:18:1: note: suggested alternative: ‘shared_ptr’
 boost::scoped_ptr<muduo::LogFile> g_logFile;
 ^~~~~
 shared_ptr
main.cpp: In function ‘void dummyOutput(const char*, int)’:
main.cpp:24:9: error: ‘g_logFile’ was not declared in this scope
     if (g_logFile)
         ^~~~~~~~~
main.cpp: In function ‘int main(int, char**)’:
main.cpp:59:9: error: ‘g_logFile’ was not declared in this scope
         g_logFile.reset(new ::muduo::LogFile(basename, rollSize, threadSafe, flushInterval, checkEveryN));
         ^~~~~~~~~
make: *** [Makefile:184: main.o] Error 1

How to run benchmark prog?

@libinzhangyuan
Happy to see your code.
I need to persistent real send data from USA to China.
So I want to run bench mark first to see the speed.
I checkout tag kcp_bench_mark_test but didn't see asio_kcp_server and asio_kcp_client.
Is there anything I did wrong?
Need your help!
Thank you very much!

Misuse ostringstream.str() ?

`void kcp_client::do_recv_udp_packet_in_loop(void)
{

if (ret_recv < 0)
{
    std::ostringstream ostrm;
    std::string err_detail = ostrm.str();
    ostrm << "do_asio_kcp_connect recv error return with errno: " << err << " " << strerror(err);
    std::cerr << err_detail << std::endl;
    return;
}

}`

client_lib 编译出错

g++ -Wall -g3 -c kcp_client.cpp -o kcp_client.o
kcp_client.cpp: In member function ‘void asio_kcp::kcp_client::do_send_connect_packet(uint64_t)’:
kcp_client.cpp:149:108: error: ‘strerror’ was not declared in this scope
std::cerr << "do_asio_kcp_connect send error return with errno: " << errno << " " << strerror(errno) << std::endl;

头文件<string.h> 在.cpp里已经包含,有谁遇见过吗?

发送大文件的时候,发送速度呈现波浪形

KCP传输
发送大文件,测试的是100M的文件,其实发送文件都会有这样的问题。
速度变动非常大,呈现出波状的。是哪里调用有问题。
发送和接收的窗宽已经都调整成3000了。
使用环境是windows7 64位的操作系统
RTT=200左右

how to filter log? why so much log?

like this log,how this log is closed? thanks!
@asio|1508310907.245388|168|[email protected]
@asio|1508310907.245393|168169|[email protected]_wait
@asio|1508310907.245400|<245400|
@asio|1508310907.250925|>169|ec=system:0
@asio|1508310907.250940|169|[email protected]
@asio|1508310907.250944|169
170|[email protected]_wait
@asio|1508310907.250949|<250949|
@asio|1508310907.256449|>170|ec=system:0
@asio|1508310907.256466|170|[email protected]
@asio|1508310907.256471|170171|[email protected]_wait
@asio|1508310907.256476|<256476|
@asio|1508310907.261937|>171|ec=system:0
@asio|1508310907.261954|171|[email protected]
@asio|1508310907.261958|171
172|[email protected]_wait
@asio|1508310907.261963|<261963|
@asio|1508310907.267578|>172|ec=system:0
@asio|1508310907.267609|172|[email protected]
@asio|1508310907.267615|172173|[email protected]_wait
@asio|1508310907.267621|<267621|
@asio|1508310907.273136|>173|ec=system:0
@asio|1508310907.273152|173|[email protected]
@asio|1508310907.273156|173
174|[email protected]_wait
@asio|1508310907.273161|<273161|
@asio|1508310907.278537|>174|ec=system:0

kcp_client_wrap

调用connect直接死循环卡死了
connect_async没有实现

UDP上用recv返回0的问题

windows下client_lib在使用的时候,会连接后立马callback断开
原因是recv传入了一个udp socket,然后recv返回0就认为断开。
但是udp是无连接的,recv返回0有可能是认为空数据包,是正常结果

asio线程安全疑问

kcp库是非线程安全的(ikcp_send/recv ikcp_input/output ikcp_update 应该在同一线程中调用)
看了一下代码 ikcp_update在timer周期回调里 接收数据在接收回调里
我想咨询一下 asio内部是单线程的吗? asio可以确保线程安全吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.