在 UDP 套接字上发送大数据 [英] Send large data on UDP socket

查看:40
本文介绍了在 UDP 套接字上发送大数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 udp 发送和接收非常大的数据.不幸的是,udp 为每个图提供 8192 字节,因此需要将数据分成更小的部分.我正在使用 Qt 和 QUdpSocket.我想发送给客户端的 QByteArray 长度为 921600.我想每次发送 8192 个字节.

I need to send and receive very large data using udp. Unfortunately udp provides 8192 bytes per diagram, so there is need to divide data into smaller pieces. I'm using Qt and QUdpSocket. There is a QByteArray with length of 921600 I want to send to client. I want to send 8192 bytes each time.

拆分 QByteArray 的快速方法是什么?

What is the fast way to split a QByteArray?

推荐答案

您可以使用 QByteArray.mid(int start, int len) 方法 (参见此处的文档)以获取从 start<开始的长度为 len 的 QByteArray/代码>.

You can use the QByteArray.mid(int start, int len) method (see documentation here) to get a QByteArray of length len starting from start.

只需将 len 设为您的数据报大小并以 0*len1*len2*len 开头>, ... 直到所有内容都发送完毕.

Just make len your datagram size and start with 0*len, 1*len, 2*len, ... until everything is sent.

这篇关于在 UDP 套接字上发送大数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆