New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP streaming transport should allow to exchange binary message #56

Closed
flowersinthesand opened this Issue Feb 2, 2015 · 2 comments

Comments

Projects
None yet
1 participant
@flowersinthesand
Contributor

flowersinthesand commented Feb 2, 2015

There are two approaches to achieve this feature.

  • Defining a new message format embracing both text and binary message.
  • Using Binary-to-text encoding with the current format.

HTTP streaming transport should be available on browser where XMLHttpRequest 2 and Typed Arrays are available like long polling transport. It will be covered in Vibe JavaScript Client first and accordingly RI will be updated.

@flowersinthesand

This comment has been minimized.

Show comment
Hide comment
@flowersinthesand

flowersinthesand Feb 3, 2015

Contributor

Following vibe-project/vibe-javascript-client#53, this feature will be implemented using Base64.

Contributor

flowersinthesand commented Feb 3, 2015

Following vibe-project/vibe-javascript-client#53, this feature will be implemented using Base64.

@flowersinthesand

This comment has been minimized.

Show comment
Hide comment
@flowersinthesand

flowersinthesand Feb 3, 2015

Contributor

Simple test.

Server

var vibe = require("./lib");
var http = require("http");
var url = require("url");

var server = vibe.transport.createHttpServer().on("transport", function(transport) {
    console.log('opened');
    transport.on("text", function(message) {
        console.log("on text", message);
        transport.send(message);
    }).on("binary", function(message) {
        console.log("on binary", message, message.toString());
        transport.send(message);
    });
});

http.createServer().on("request", function(req, res) {
    if (url.parse(req.url).pathname === "/vibe") {
        server.handle(req, res);
    }
}).listen(8080);

// > opened
// on text hello
// on binary <Buffer 68 65 6c 6c 6f> hello

Client

var vibe = require("./lib");
var transport = vibe.transport.createHttpStreamTransport("http://localhost:8080/vibe?transport=stream");
transport.on("open", function() {
    console.log('opened');
    transport.send("hello");
    transport.send(new Buffer([104,101,108,108,111])); // equals to new byte[]{'h','e','l','l','o'}
}).on("text", function(message) {
    console.log("on text", message);
}).on("binary", function(message) {
    console.log("on binary", message, message.toString());
}).open();

// > opened
// on text hello
// on binary <Buffer 68 65 6c 6c 6f> hello
Contributor

flowersinthesand commented Feb 3, 2015

Simple test.

Server

var vibe = require("./lib");
var http = require("http");
var url = require("url");

var server = vibe.transport.createHttpServer().on("transport", function(transport) {
    console.log('opened');
    transport.on("text", function(message) {
        console.log("on text", message);
        transport.send(message);
    }).on("binary", function(message) {
        console.log("on binary", message, message.toString());
        transport.send(message);
    });
});

http.createServer().on("request", function(req, res) {
    if (url.parse(req.url).pathname === "/vibe") {
        server.handle(req, res);
    }
}).listen(8080);

// > opened
// on text hello
// on binary <Buffer 68 65 6c 6c 6f> hello

Client

var vibe = require("./lib");
var transport = vibe.transport.createHttpStreamTransport("http://localhost:8080/vibe?transport=stream");
transport.on("open", function() {
    console.log('opened');
    transport.send("hello");
    transport.send(new Buffer([104,101,108,108,111])); // equals to new byte[]{'h','e','l','l','o'}
}).on("text", function(message) {
    console.log("on text", message);
}).on("binary", function(message) {
    console.log("on binary", message, message.toString());
}).open();

// > opened
// on text hello
// on binary <Buffer 68 65 6c 6c 6f> hello
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment