xtaci / kcp-go

A Crypto-Secure Reliable-UDP Library for golang with FEC
MIT License
4.09k stars 733 forks source link

多客户端连接连接至同一个服务器的时候,如果有一个客户端断开了,服务端就会停止广播,即使客户端重新连接,服务端也收不到任何的连接信息,需要服务端重启才能解决此问题 #262

Open FlashFeiFei opened 6 months ago

FlashFeiFei commented 6 months ago

go:kcp-go作为服务端 java:kcp-base作为客户端

go作为游戏数据转发

FlashFeiFei commented 6 months ago

服务端代码 `package main

import ( "github.com/xtaci/kcp-go/v5" room2 "kcp/demo3/room" "log" "time" )

func main() {

listener, err := kcp.ListenWithOptions("127.0.0.1:12345", nil, 10, 3)
listener.SetDeadline(time.Now().Add(1 * time.Second))
if err != nil {
    log.Fatal(err)
}

room := room2.NewGameRoom()
go room.Run()
for {
    s, err := listener.AcceptKCP()
    if err != nil {
        continue
    }
    room.JoinChan() <- s
}

} `

FlashFeiFei commented 6 months ago

客户端代码 `package com.laughingZhu.api;

import com.backblaze.erasure.FecAdapt; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.Unpooled; import kcp.ChannelConfig; import kcp.KcpClient; import kcp.KcpListener; import kcp.Ukcp;

import java.net.InetSocketAddress; import java.nio.charset.StandardCharsets;

/**

}`

FlashFeiFei commented 6 months ago

先运行服务端,然后运行客户端,一切正常 微信图片_20240413005401

FlashFeiFei commented 6 months ago

这时候,断开客户端重新运行客户端之后,数据会发送几秒,之后就不在发送数据了,卡主了;重新开启一个客户端,debug服务端发现s, err := listener.AcceptKCP()没有链接进来 微信图片_20240413005859

luodaoyi commented 6 months ago

求个c++的例子

FlashFeiFei commented 6 months ago

微信图片_20240428142926