kcp icon indicating copy to clipboard operation
kcp copied to clipboard

正常发送接收了, 但同一条数据发送 32次以后,发送端的ikcp_setoutput 回调就不执行了

Open LiQingYues opened this issue 3 years ago • 9 comments

求大神指导 kcp = KCP.ikcp_create(0, (void*)0); KcpUser cq = delegate (byte[] array, int v) {

        };
        KCP.ikcp_setoutput(kcp, delegate (byte* data, int len, IntPtr kcp, void* v) {

            byte[] buff = new byte[len];
            Marshal.Copy(new IntPtr(data), buff, 0, len);
            socket.Send(buff);
        });

        KCP.ikcp_wndsize(kcp, 512, 512);
        KCP.ikcp_nodelay(kcp, 1, 10, 2, 1);
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
        socket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8500));
        RunThread();

//发送部分代码 while (true) { KCP.ikcp_update(kcp, (uint)Environment.TickCount); Thread.Sleep(1000); index += 1; string fuck = "我是大坏蛋呀!!"+index; var bytes = System.Text.Encoding.UTF8.GetBytes(fuck); int len = KCP.ikcp_send(kcp, bytes, bytes.Length); KCP.ikcp_flush(kcp);; }

LiQingYues avatar Apr 27 '21 09:04 LiQingYues

还是 ikcp_recv 一直返回-1 悲伤

LiQingYues avatar Apr 27 '21 10:04 LiQingYues

已解决,,,客户端没处理ack....

LiQingYues avatar Apr 27 '21 10:04 LiQingYues

请问一下客户端ack是怎么处理的

Cr7st avatar Jun 23 '22 02:06 Cr7st

我现在就是有一个问题就是假如我客户端一直发消息,客户端也进行了ack处理,服务端接收到某一个次数后就不接受了,比如说接收了1000次就停止了

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho

这是服务端代码 `ikcpcb *kcp = ikcp_create(1, (void *) &addrClient); kcp->output = udp_output; ikcp_nodelay(kcp, 1, 1, 2, 1); ikcp_wndsize(kcp, 128, 128);

int count=0;
while (1) {
    //Sleep(100);
    ikcp_update(kcp, clock());
    // 打印来自客户端发送来的数据
    while (1) {
        nRet = recvfrom(socketSrv, buf, BUF_SIZE, 0, (SOCKADDR *) &addrClient, &len);

/* if (nRet < 0){ int y = WSAGetLastError(); //printf(" WSAGetLastError(); %d\n", y); break; }*/ ikcp_input(kcp, buf, nRet); ikcp_update(kcp, clock()); ikcp_flush(kcp);

        hr = ikcp_recv(kcp, kcpbuf, BUF_SIZE);
        if (hr > 0) {
            count = count + 1;
        }
        printf("I recv :%s,count is  %d  \n", kcpbuf, count);
        // 没有收到包就退出
        //if (hr < 0) break;
        // 如果收到包就回射一个空包,里面应该是有KCP里处理好的包序号以及Ack信息
        ikcp_send(kcp, blankbuf, strlen(blankbuf) + 1);
        ikcp_update(kcp, clock());
        ikcp_flush(kcp);
    }

`

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho

这是客户端代码

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho

` ikcpcb *kcp = ikcp_create(1, (void *) &servAddr); kcp->output = udp_output; ikcp_nodelay(kcp, 1, 1, 2, 1); ikcp_wndsize(kcp, 128, 128);

long start, current;

start = clock();
long slap = clock();
int index = 1;
while (1) {
    //Sleep(100);
    //printf("OK\n");
    current = clock();
    //
    ikcp_update(kcp, clock());

    int res;

    //if (current - start < 1000) {
        for (; current >= slap; slap += 10) {
            //char        temp[BUF_SIZE];
            //sprintf(temp,"%s_%d",buf,index);
            printf("ikcp send: %d  ", index);
            ikcp_send(kcp, buf, strlen(buf) + 1);
            ikcp_update(kcp, clock());
            ikcp_flush(kcp);
            index++;

            nRet = recvfrom(sockClient, recvbuf, BUF_SIZE, 0, (sockaddr *) &servAddr, &nServAddLen);
            //if(nRet < 0) break;
            ikcp_input(kcp, recvbuf, nRet);
            ikcp_update(kcp, clock());
            ikcp_flush(kcp);

            char kcpbuf[BUF_SIZE];
            ikcp_recv(kcp, kcpbuf, BUF_SIZE);
            //if(hr < 0) break;
            // 打印来自服务端发送来的数据
            printf("Recv From Server:%s\n", kcpbuf);
            ikcp_update(kcp, clock());
            ikcp_flush(kcp);
        //}
    }`

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho

抱歉了,github这个贴代码的工具好像有bug

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho

麻烦问一下各位大佬这里面有哪些逻辑错误呢,十分期待您的回复!

SarahSmitho avatar Sep 07 '22 13:09 SarahSmitho