I'm working on a simple game, that needs to use Web Sockets. I have read that DDP should be the way to go, as it's what Meteor uses.
I can't find any documentation regarding it tho, except the note on Meteor.com.
Should I use sock js instead, or how can I use the DDP package?
DDP is a protocol that can run on top of sockets. It's not a socket library in itself. If you really need your own socket communication, then use socket.io or look for packages that do that on atmosphere. There have been some attempts made (e.g., http://arunoda.github.io/meteor-streams/), but I'm not sure what the latest is on that. This might work for you: https://github.com/joncursi/socket-io-client
Related
I seem to be confused by conflicting sources, yesterday I was reading the node docs and was sure Node's 'net' and 'http' modules had web socket capabilities, but maybe I misunderstood the documentation because today an article said that node has no built in web socket support.
Can you create a node server that can handle web socket connections with just node and javascript, no external libraries?
Node does not have native support for websockets like it does for http or tcp (net) connections.
It's been discussed a few times, and rejected for various reasons of the last few years. The current discussion is going on here: https://github.com/nodejs/node/issues/19308
You can, of course, implement a websocket server yourself using the native modules, but you'll need to do a lot of boilerplate work.
To see both an example of what you'd need to do to implement your own websocket server using node and a good pre-built library you can use to work with websockets in node, I would reccomend taking a look at: https://github.com/websockets/ws
Sure, you could... if you re-implemented the functionality from those Web Socket libraries yourself.
The Node.js core libraries are minimal. They're only intended to cover the basics needed to function, and the most common use cases. As much functionality as possible is left to modules outside of the Node.js core. This is a very intentional design.
It would be incredibly irresponsible to implement your own Web Socket library without a very good reason. You should rethink why you don't want to use existing libraries.
Due to restrictions on node.js versions, recent versions of Meteor cannot be used on the system. A DDP server has to be created using regular node.js instead, which a Meteor setup will connect to.
DDP client can be created in node.js using node-ddp-client, but how can we create a DDP server?
It might be too late to answer this and this might not be a good answer anyway. It's not an easy task, we need to manage sessions, users, methods, publications... As a reference for a brave developer :)
We need EJSON or some other implementation to serialize and deserialize messages between client and server.
We need a socket server (sockjs would be a good choice since meteor is using it too.)
We need to implement DDP specification
I've found https://www.npmjs.com/package/ddp-server-reactive and https://www.npmjs.com/package/ddp-server which both seem to do the job
Will be a support of raw sockets in node.js, e.g. to create ping packets?
A new module named node-raw-socket offers the perfect solution for real raw sockets using nodejs.
And, for creating ping (ICMP) packets, the same developer has a very nice working (using it) solution based on node-raw-sockets as well: node-net-ping.
Node supports TCP, UDP, and unix sockets. Ping packets are ICMP packets, which node cannot create directly at this time. You could execute an external ping subprocess or consider writing a C extension. Most of node's low level OS APIs are thin javascript wrappers around the corresponding C API, so you could follow that existing well-established pattern and implement this as a small JS wrapper layer around the corresponding OS-level APIs.
http://nodejs.org/docs/latest/api/all.html#all_class_net_socket
There's a chance node/javascript are a poor choice for your project based on this requirement though.
net-ping module may suit your need. to install it you can use the following command:
npm install net-ping
The documentation with examples is included here.
I want to create something similar to Heroku (first I was thinking in EngineYard-like but I prefer Heroku) for node.js (I know they already support node.). However, It's for a personal project so it doesn't need to be anything overcomplicated or super expensive. I believe I can learn a lot creating a product like this.
Before I start, I have several doubts:
Heroku uses a reverse proxy to receive the requests. However, reverse proxy doesn't work fine with websockets. How can this be fixed?
1 instance supports several dynos. How can an instance be divided by RAM, processing, etc?
I guess if I have an answer to the last questions I'll be able to create a route mesh. However, what can be the tricks here?
Regards.
Donalds
So you want to be a node Paas?
Nodejitsu opensourced their hosting solution: haibu (Japanese for Hive). It's well documented and you'll also get real time support if you hope onto #nodejitsu on efnet irc network.
As a user of their service, I can vouch for the simplicity of the solution. You use their client jitsu to provision, configure and deploy the applications. Applications are watched over by their tweaked version of forever.
Go for the simplest possible implementation.
Use HAProxy, Apache Traffic Server or
mongrel2 as your reverse proxy. They
all support the HTTP 1.1 protocol and
should work with websockets.
Don't worry about limiting resources.
Also don't worry about a routing mesh.
Just update and reload the
config on your reverse proxy any time
you're spinning up a backend process.
Good luck.
I'm thinking about how limiting it is for AJAX apps to have to poll for updates, when what would be ideal is for javascript to be able to set up a real two way connection to the server. I'm wondering if there is some method of integrating javascript with a browser plugin that can make a tcp connection so that I could pass data into and out of the browser plugin.
WebSockets is designed to solve this problem.
Here is an implementation with a similar approach:
socketjs
It uses a Java Applet and bridges its API to JavaScript, interesting...
And here another one:
jSocket
This one is a wrapper of the Actionscript 3 Socket API, bridged to JavaScript...
You can use node.js framework's socket.io package which can can be installed via npm (A node package manager).
More detailed usage.
jSocket and Stream are two options that utilize Flash's built-in XML sockets, though neither appears to be production-ready. I'd lean towards using a Flash-based solution rather than Java, as browser penetration is higher and generally offers a better user experience (load times & stability).