Git Product home page Git Product logo

Comments (7)

youurayy avatar youurayy commented on August 28, 2024

If you use Express or Connect, check this package for seamless Flash shim integration (along with the policy server):

https://github.com/ypocat/ws-flash-client

It's the same code as web-socket-js (btw. socket.io uses it too for the Flash transport), but repackaged for Express/Connect.

If you don't use Express or Connect, you may just use the policyfile one-liner to achieve this:

require('policyfile').createServer().listen(prod ? 843 : 10843[, yourHttpServerIfAny]);

I would love if ws stayed clean and only focused on the core WebSocket protocol support.

from ws.

einaros avatar einaros commented on August 28, 2024

It is supported in the sense that socket.io (and others) depending on ws
can supply their own web server instance to ws and either use the common
listener or handleUpgrade for specific control.

On Feb 23, 2012 5:25 PM, "Joel Martin" <
[email protected]>
wrote:

web-socket-js is the Flash based polyfill/shim for browsers without native
support. Flash sockets implement their own form of CORS in the form of a
Flash policy response (on port 843 and then on the target port). Answering
inline on the same port is supported in Socket.IO and websockify, etc. It
would be nice if einaros/ws supported answering Flash policy requests so
that it could be used with web-socket-js.


Reply to this email directly or view it on GitHub:
#28

from ws.

kanaka avatar kanaka commented on August 28, 2024

@ypocat, yeah, that's perfect (especially after discovering I can force inline only by passing -1 for the port.

@einaros, you might consider mentioning the option suggested by @ypocat in the README so that people looking to use web-socket-js with einaros/ws will have clear direction.

from ws.

einaros avatar einaros commented on August 28, 2024

@ypocat ws definitely will stay lean and mean. This is, as you point out, easily implemented by abstractions utilizing ws or other transports.

@kanaka What would you like me to mention? There are three options with regard to server: have ws create it itself, supply a server or use handleUpgrade directly. Between the three it should be possible to handle most scenarios.

from ws.

kanaka avatar kanaka commented on August 28, 2024

That actually reminds me, I think it would also be helpful to show an example of using ws in combination with an http server. So perhaps you could add another example to the README, something like this:

Here is an example of combining ws with an http server so that both listen on the same port. In addition the 'policyflie' module is used to answer inline Flash policy requests to support browser clients using the web-socket-js polyfill.

httpServer = http.createServer(function (req, res) {
    console.log("got http request");
});
httpServer.listen(8080, function() {
    wsServer = new WebSocketServer({server: httpServer});
    wsServer.on('connection', function (client) {
        console.log("new WebSocket client");
    });
});
// Attach Flash policyfile answer service
policyfile.createServer().listen(-1, httpServer);

from ws.

youurayy avatar youurayy commented on August 28, 2024

@einaros as for writing useful info into the ws README.md - I think for many people who use Express, it would be beneficial to include a link to ws-rpc, which contains a pretty thorough example on how to get ws running with Express with the same (relevant) functionality as socket.io.

@kanaka I don't think many people use naked Node's http server these days, but the ws-rpc is possible to be used there as well, as is ws-flash-client, but for the flash client I need to update the readme on how to use it without Express.

from ws.

richardfburton avatar richardfburton commented on August 28, 2024

httpServer = http.createServer(function (req, res) {
console.log("got http request");
});
httpServer.listen(8080, function() {
wsServer = new WebSocketServer({server: httpServer});
wsServer.on('connection', function (client) {
console.log("new WebSocket client");
});
});
// Attach Flash policyfile answer service
policyfile.createServer().listen(-1, httpServer);

Does not work on same port

from ws.

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.