Code Monkey home page Code Monkey logo

kcpuv's Introduction

KCPUV

使用KCPlibuv的简单网络模块。

用法

  • 创建kcpuv对象
kcpuv_t kcpuv = kcpuv_create();
  • 如果用作服务器,那么监听UDP端口
kcpuv_listen(kcpuv, "0.0.0.0", 9527);
  • 如果用作客户端,那么创建连接
kcpuv_conv_t conv = 0x12345678; // 定义回话ID
kcpuv_connect(kcpuv, conv, "127.0.0.1", 9527);
  • 处理网络消息
void process_network() {
	// 让kcpuv处理一下内部事务
	kcpuv_run(kcpuv);

	kcpuv_msg_t msg;
	while (true) {
		// 接收消息
		int r = kcpuv_recv(kcpuv, &msg);
		if (r < 0) break;

		// 处理消息
		// ...

		// 销毁消息
		kcpuv_msg_free(&msg);
	}
}
  • 发送消息
const char* data = "hello";
uint32_t size = 5;
kcpuv_send(kcpuv, conv, data, size);

版本状态

目前版本处于DEMO阶段,一些显而易见的问题还没有处理:

  • 回话ID(conv)是客户端分配,服务器不做任何处理,全盘接受。
  • 内存分配和释放很粗放。
  • ...

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.