Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

KCP在高延迟环境下怎样使用才能满足大流量,而不是快速响应? #406

Open
haozia816 opened this issue Mar 21, 2024 · 3 comments

Comments

@haozia816
Copy link

haozia816 commented Mar 21, 2024

我们需要同时工作在TCP和UDP协议中,所以选择了使用KCP,但是我的软件中还需要传输文件,我测试了在高延迟(1s)环境中,TCP协议、2048的窗口也只能达到400k左右的速度,还经常出现传输中断,ikcp_input后KCP再无任何响应。请问在高延迟环境中,只要求大流量而不要求快速响应我应该怎么使用呢?
无延迟环境测试为16M/S

@jiangguilong2000
Copy link

jiangguilong2000 commented Mar 21, 2024 via email

@skywind3000
Copy link
Owner

自己再 issue 里翻翻,别人传输速度比你这个快。

@haozia816
Copy link
Author

haozia816 commented Mar 22, 2024

自己再 issue 里翻翻,别人传输速度比你这个快。

麻烦大神指导下呢,没有找到相似的issue,我是asio实现的,下面是伪代码

boost::asio::stready_timer	m_timer;

void active_update()
{
	ikcp_update(m_kcp);
	m_timer.expires_at(ikcp_check(m_kcp));
	m_timer.async_wait([]
	{
		active_update();
	});
}

//实例启动
void start()
{
	//开启周期性update
	active_update();
}

//网络接收到数据
void handle_recv(const uint8_t* data, size_t size)
{
	ikcp_input(m_kcp, data, size);
	while (true)
	{
		int len = ikcp_recv(m_kcp, buffer1);
		if(len == -1)
		{
			break; //无可用数据,结束while循环
		}
		//处理KCP接收到的数据,存储在buffer1中
		......
	}
	while (ikcp_waitsnd(m_kcp) < m_kcp->snd_wnd * 2)
	{
		//发送队列未满,继续读取文件发送
		if (pf) //FILE* pf;
		{
			fread(buffer2, 1, m_kcp->mss, pf);
			ikcp_send(m_kcp, buffer2, m_kcp->mss);
			active_update(); //测试过这里只能执行ikcp_update,执行ikcp_flush的话,数据不会立刻发送
		}
		else
		{
			break;
		}
	}
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants