用beginreceivees还是用 beginreceivee?为什么

问题对人有帮助,内容完整,我也想知道答案
问题没有实际价值,缺少关键内容,没有改进余地
我想使用Websocket来上传大文件.为了避免将大文件一次性读入内存,我将文件进行切块发送.下面是我的JS代码:
function upload() {
var slicesize = ;
var file = document.getElementById("file").files[0];
var ws = new WebSocket("ws://127.0.0.1:8080/file");
var startsize = 0;
var endsize = 0;
ws.onopen = function () {
console.log("成功连接到服务器");
ws.send(file.name);
console.log("size : ", file.size);
console.log("name size : ", file.name.length)
ws.onmessage = function (resp) {
console.log("收到来自服务器的信息: ", resp.data)
if (endsize & file.size + file.name.length) {
console.log("test")
startsize =
endsize +=
var blob = file.slice(startsize, endsize);
var reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = function loaded(event) {
var arrayBuffer = event.target.
ws.send(arrayBuffer);
console.log("发送切片")
startSize = endSize = 0;
console.log("全部发送完成!")
ws.onclose = function () {
console.log("成功关闭了连接")
后端我使用Go语言进行处理,使用的是"golang.org/x/net/websocket"这个包.相关代码如下:
func UploadFile(ws *websocket.Conn) {
var err error
var count int
var recData bytes.Buffer
var filename string
var savepath string
var receive []byte
if err = websocket.Message.Receive(ws, &receive); err != nil {
log.Fatal(err)
if count == 0 {
filename = string(receive)
fmt.Println("文件名为: ", filename)
recData.Write(receive)
sent := strconv.Itoa(len(receive))
fmt.Println("本次接受到的文件长度为: ", len(receive))
fmt.Println("发送了: ", sent)
if err = websocket.Message.Send(ws, sent); err != nil {
log.Fatal(err)
现在遇到的问题是尝试发送一个6m的文件,前端和后端不断进行了send和receive,但是6m多的文件只需要在js里面send两次就好了,一次是send文件名,另外一次是真实传送文件数据.后端接受js这两次send事件后,返回收到的数据(字节)的长度给js.但是浏览器的控制台输出是这样的:
成功连接到服务器
upload.html:53 size :
upload.html:54 name size :
upload.html:57 收到来自服务器的信息:
upload.html:59 test
upload.html:68 发送切片
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
upload.html:57 收到来自服务器的信息:
upload.html:72 全部发送完成!
我很疑惑为什么后面会出现这么多send和receive事件 ? 有谁能不能帮我解答下?这是我第一次使用Websocket
答案对人有帮助,有参考价值
答案没帮助,是错误的答案,答非所问
ws 读取数据并不是等你把所有数据全部上传完毕在一次性读出来的比如我有10m数据我带宽只能1ms传1mgo端的ws for无限监听ws内的待读取数据,这个循环是有时间差的,比如1ms读取一次,读到后就返回,这个时候是不管你send完没send完都会返回我1ms上传1m,后端1ms读取一次,那每次就只能读到1m,然后10次读完。js端你send了两次,中间是有时间间隔,所以后端读取第一次filename后是完整读的,这个发送速度快,一次完成send 文件内容6m这个慢,在send没完成前,后端就会一次一次的读取,每次都是for时间间隔内所发送的数据。所以上传这种大文件,最好加上文件上传结束标识,来告诉后端我send结束了。ws我理解着应该是这样子的,不知道对不对
分享到微博?
Hi,欢迎来到 SegmentFault 技术社区!⊙▽⊙ 在这里,你可以提出编程相关的疑惑,关注感兴趣的问题,对认可的回答投赞同票;大家会帮你解决编程的问题,和你探讨技术更新,为你的回答投上赞同票。
明天提醒我
关闭理由:
删除理由:
忽略理由:
推广(招聘、广告、SEO 等)方面的内容
与已有问题重复(请编辑该提问指向已有相同问题)
答非所问,不符合答题要求
宜作评论而非答案
带有人身攻击、辱骂、仇恨等违反条款的内容
无法获得确切结果的问题
非开发直接相关的问题
非技术提问的讨论型问题
其他原因(请补充说明)
我要该,理由是:用Matlab中的TCP/IP
Receive模块怎么能通过以太网接收到数据?【matlab吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:174,860贴子:
用Matlab中的TCP/IP
Receive模块怎么能通过以太网接收到数据?收藏
本人刚学习Matlab不久,现在正在研究一个通过以太网收发数据的例子,现用TCP/IP
Send模块可以成功的将数据发送出去,可是用TCP/IP Receive模块却接收不到通过以太网发送来的数据,不知道为什么。请高手指教!谢谢。。
免费下载官方MATLAB中文试用版,让工程师和科学家更高效地进行科学计算.
正在研究,楼主解决了吗
登录百度帐号推荐应用用receives还是用 receive?为什么?_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
用receives还是用 receive?为什么?
Only about one out of twelve of the young men and women of this country (
)college education
A. receive
B. receives
C. have received
D. have been received
为什么要用单数不用复数?答案是B。。
不是说要看后面的名词么?...
很遗憾,one out of twelve虽然表示出了分数的意思,但不是分数。one是主语,后面的一大堆都是来修饰one的。真正的分数应该是 one twelfth,如果是这样的分数作主语时才是看后面的名词!
采纳率:48%
12的话 很明显就是单数第三人称形式了。所以1&#47.这个国家的男人跟女人是来具体化1/12这个主语Only about one out of twelve (of the young men and women of this country)所以主谓一致的话,应该是看1/12
你好好学习一下分数。 分子是一的话就用单数,大于一用复数。
其他1条回答
为您推荐:
其他类似问题
等待您来回答}

我要回帖

更多关于 c beginreceive使用 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信