Comments (7)
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.
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.
@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.
@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.
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.
@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.
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)
- query: difference between ws.onmessage = handler and ws.on('message', handler) HOT 2
- Messages are dispatched while microtask queue is not empty HOT 6
- Uhhh, what does .isAlive do again? HOT 2
- RangeError: Invalid WebSocket frame: MASK must be set HOT 1
- Invalid dns names should not cause an uncatchable fatal exception HOT 2
- Incorrect/incomplete documentation HOT 3
- Catching message exceeding maxPayload without automatically closing the connection HOT 4
- No way to detect half-closed websockets HOT 4
- Error: Unexpected server response: 404 HOT 6
- Invalid UTF-8 sequence even though the message is encoded HOT 4
- Throws TypeError when there are too many HTTP headers HOT 3
- Source Code Confusion HOT 3
- DoS HOT 2
- Cannot add async functions to server.upgrade. Causes client connection close during the authentication. HOT 6
- Contribution Proposal and Chinese Documentation Request for WS Library HOT 2
- Bug: v8.18.0 released major breaking change (not minor) and data sent as Blob (not Buffer) HOT 7
- [Feature]: Improve Project's JSDoc Types HOT 27
- Type in @types/ws for server address is wrong HOT 1
- Build warning: Can't resolve 'bufferutil' HOT 3
- How to unsubscribe from a topic HOT 2
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 ws.