Categorygithub.com/0990/kcp2k-go
modulepackage
0.0.0-20240605104828-96c0ad5bb30d
Repository: https://github.com/0990/kcp2k-go.git
Documentation: pkg.go.dev

# README

kcp2k-go

中文文档
A Golang implementation of Mirror kcp (kcp2k)
Ready to use, can communicate directly with Mirror kcp

Introduction

The kcp2k included with the Mirror game framework customizes a communication protocol based on the underlying kcp protocol
Main feature comparison:

Transmission FeaturesHandshake and Close
KCP2KSupports reliable and unreliable transmissionSupported
KCPSupports reliable transmission onlyNot Supported

Examples

simple example

kcp2k Encoding

Adds a kcp2kHeader on top of the original transmission packet to support distinguishing between reliable and unreliable transmissions

1 byte4 bytes
channelcookie

channel:

  • 1 Reliable Transmission
  • 2 Unreliable Transmission

The cookie is a "credential" after the connection is established, and its official purpose is:

generate a random cookie for this connection to avoid UDP spoofing

Reliable Transmission Encoding

Mirror kcp supports handshake and close, with the first byte of the transmitted data being the control bit

type Kcp2kOpcode byte

const (
    Hello      Kcp2kOpcode = 1
    Ping       Kcp2kOpcode = 2
    Data       Kcp2kOpcode = 3
    Disconnect Kcp2kOpcode = 4
)

The final raw encoding sent via udp is:

1 byte4 bytes24 bytes1 byteN bytes
0x01cookiekcp protocolKcp2kOpcodedata

Unreliable Transmission Encoding

Unreliable transmission encoding is simpler, as follows:

1 byte4 bytesN bytes
0x02cookiedata

Additional Information

kcp-go need exposing the interface to read a whole kcp data packet from the UDPSession
So, I forked and modified it: https://github.com/0990/kcp-go

# Packages

No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
封装给kcp-go UDPSession的Conn 1,mirror kcp有可靠传输和非可靠传输,在读取conn时,根据头部的第一个字节来识别,将识别为可靠传输的投喂给KcpUnderlyingConn(packetInput) 2,kcp-go UDPSession再通过ReadFrom来读取可靠流 3,kcp-go UDPSession通过WriteTo来输出流,mirror kcp需要增加头部自定义字段再发送出去,详见:Session.KCPOutput.
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author