Giter VIP home page Giter VIP logo

Comments (6)

jocull avatar jocull commented on May 20, 2024 3

It seems to work as long as you consistently use ArrayBuffer and related views on both sides.

If you send a Buffer type from Node something seems to get crossed and an empty ArrayBuffer appears on the other side.

server.on('connection', socket => {
  socket.on('message', (msg) => {
    const encodedAsNodeBuffer = myBufferGenerator();
    const newBuffer = new ArrayBuffer(encodedAsNodeBuffer.byteLength);
    const newBufferView = new Uint8Array(newBuffer);
    newBufferView.set(encodedAsNodeBuffer, 0);
    socket.send(newBuffer);
  }
}

The protobufjs code generator seems to use Buffer on the Node side, so something to be aware of if you are using that.

from mock-socket.

thoov avatar thoov commented on May 20, 2024

@dtracers right now there is no native support for binary messages but it will be on of the next things I work on adding.

from mock-socket.

cades avatar cades commented on May 20, 2024

+1

from mock-socket.

thoov avatar thoov commented on May 20, 2024

@cades or @dtracers do you have any examples I could use as a test case? If so I will be able to add support quickly

from mock-socket.

dtracers avatar dtracers commented on May 20, 2024

I use protobuf.js.

So a good example test might be sending a hello world protobuf file via
binary.

I don't think I'll be able to come up with one until this weekend. And
maybe not even then.
On Jun 5, 2015 11:01 AM, "Travis Hoover" [email protected] wrote:

@cades https://github.com/cades or @dtracers
https://github.com/dtracers do you have any examples I could use as a
test case? If so I will be able to add support quickly


Reply to this email directly or view it on GitHub
#6 (comment).

from mock-socket.

nomve avatar nomve commented on May 20, 2024

I don't know if something changed in the meantime, but this works:

    var binaryDataBuffer = new ArrayBuffer(1),
        binaryDataArray = new Uint8Array(binaryDataBuffer);

    clientInstance.onmessage = function(event) {
        var data = new Uint8Array(event.data);
        QUnit.equal( data[0], 1, "didn't receive the right data" );
    };

    binaryDataArray[0] = 1;
    serverInstance.send(binaryDataBuffer);

from mock-socket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.