Skip to content

视频传输后,虽然能播放但会出现花屏 #14

@FI-GGG

Description

@FI-GGG
//我是使用 require('stickpackage/index').stick自定义头来做的

//发送方  connect是与服务器的连接的socket
r = fs.createReadStream('./a/1.mkv')
        r.on('data', (chunk) => {
            const headBuf =Buffer.alloc(4);
            headBuf.writeUInt32BE(chunk.byteLength, 0);    
            const data=Buffer.concat([headBuf,chunk]) ;      //组合头+信息,发送
            if (connect.write(data) == false) {  
                r.pause()
            }
        })

//接收方  client  是连接到服务器的socket
 //设置解包用缓冲区大小
        client.stick = new stick_package(1024).setReadIntBE('32');
        //解包处理函数 data是 包头+包体
        client.stick.onData( data=> {
            // 解析包头长度
            const head = Buffer.alloc(4);    
            data.copy(head, 0, 0, 4);
            // 解析数据包内容
            const body = Buffer.alloc(head.readInt32BE());
            data.copy(body, 0, 4, head.readInt32BE());

            if (w.write(body) == false) {
                client.pause()
            }
            //head 包头    body包体
            // console.log('data length: ' + head.readInt32BE());
            // console.log('body content: ' + body.toString());
        });

        client
            .on('data', (chunk) => {
                client.stick.putData(chunk);
                // client.msgCenter.putData(chunk)

            })

  //我自定义信息头会导致乱码,如果直接用msgCenter的就没问题了,可我看代码应该没什么问题啊

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions