Comments (6)
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.
@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.
+1
from mock-socket.
@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.
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.
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)
- Security vulnerability in url-parse dependency HOT 2
- Is this repo still maintained? HOT 5
- Using QueryParams in ws url doesn't work HOT 1
- How to mock Apollo client to test graphql subscription HOT 1
- Add `connectionDelay` option to Server to delay opening connection
- Mock ws inside web worker HOT 3
- Authorization Bypass Through User-Controlled Key in NPM url-parse prior to 1.5.8. HOT 2
- Delay execution of dispatched events HOT 5
- Enable and disable MockSocket at runtime HOT 2
- mock-socket configuration issue ? HOT 1
- Playwright example HOT 3
- [Typescript] Client.addEventListener and Server.addEventlistener has wrong typing HOT 1
- send should throw an error if readyState is CONNECTING HOT 1
- Bug in ws client mock - wrong close code when server not found HOT 1
- Export `CloseEvent` HOT 1
- Spec doesn't actually say that `send()` should throw when the socket is `CLOSING` or `CLOSED` HOT 2
- Calling `close()` in the `CONNECTING` state should not result in open callback being called
- Do you need to import the WebSocket in this example? HOT 4
- The socket-server stops after 1 message is emitted HOT 4
- Apparently, test.cb() has been deprecated by ava HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mock-socket.