I want to make public WebSocket API with sails.js. So I'd like to use native WebSockets instead of the built-in socket.io but with Sails.js controllers and models. Is it possible? Maybe I can implement custom transport or something else. Thanks for any help.
I implemented WebSockets support for Sails.js as a custom hook:
https://github.com/provectus/sails-userhooks-ws
Using raw socket.io functionality in a Sails.js controller
https://gist.github.com/mikermcneil/6598661
Related
Using Sanic, you can handle websockets connections using #app.websocket('/socket.io/') but the protocol used in Socket.io is specific.
Python has Python-Socketio as a module to handle Socket.Io specific communications, but they recommend to use the code like this :
sio = socketio.AsyncServer(async_mode='sanic')
app = Sanic()
sio.attach(app)
#sio.on('connect')
def on_connect():
...
So, which one should be used? Should we implement SocketIo protocol inside #app.websocket from Sanic, or should we ignore this and directly use the implementation from SocketIo?
I'm asking for both rapidity and best practice here. If the best decision is to go with #app.websocket, how can we set up Socket.io inside the Sanic handler?
The Socket.IO protocol is very complex, it will take you a decent amount of time to implement it all manually in the websocket route. Also note that Socket.IO uses the same route for HTTP and WebSocket, something that I understand it is not possible to do (easily, at least) with Sanic.
The python-socketio package integrates with many frameworks, including Sanic to implement all the details of the Socket.IO protocol.
I have a fundamental question about Reactjs and Mongodb. I want to build a react app which has a "search" feature that shows results from the database. However, I have an issue on understanding how to implement the connection between the react app and the database.
Sorry for the general question. Every help or hint on how to proceed will be appreciated. Thanks in advance.
React is completely back-end agnostic. Which means you would have to implement the connection yourself.
The regular way is, you setup MongoDB and a Node.js server (or whatever back-end you like) then you connect the Node.js server to MongoDB (via MongoDBs JavaScript SDK) and your React client, which runs in the browser to your Node.js server (via HTTP, express framework could help here).
Browser -> Node.js -> MongoDB.
But MongoDB also has a REST interface you could use directly via the browser, like it's mentioned in the following answer:
https://stackoverflow.com/a/16277603/1016383
Would probably be okay for small proof of concepts or experiements,.
These days I try to develop real time application using nodejs.
That application want to update the dashboard according to api data.
I installed express and faye and try to compare what is the best and what are the differences of that two.
As I know express is a node base framework and faye is a subscriber/publisher based one.
But I think both are almost same and anyone can help me to identify the differences?
What is fast and what can be done using the frameworks like that ?
Thanks in advance.
They are not very comparable. If you want to create a real-time application, you will probably need to use both.
Express is a web framework. You will need it to serve and handle HTTP requests and responses. It will help you handle things like url routing, request/response handling middleware, interfacing with template engines, etc... Express is as fast as you'll get.
Faye is a pub sub messaging system- It will not be capable of handling standard HTTP requests and responses. You may be able to implement a live stream of the data using Faye, however, you will still have the need to serve up your client side application using Express.
I would also look into Socket.io as an alternative to Faye- in addition to Express.
I use node.js.
I am looking for an alternative for socket.io.
I need to send a private message to the user.
What is the alternative for the SOCKET.IO?
You haven't really explained why you're looking for Socket.IO. If you provide more details into why Socket.IO isn't working for you then you can get a better answer. Otherwise I'll just point you to a duplicate of this question.
Node.JS Looking for an alternative to socket.IO
I've made nodejs application by this template. And now I want to add simple websocket chat.
My question is: do I have to completely rewrite that application to add websocket chat or I can to save that structure?
You can create a chat using Socket.IO (or another library), it's perfectly possible (and probably a best practice even) to separate the two: the regular server and the WebSocket server.
The two aren't tied together.
I have never used the express MVC template, but socket.io does not use express routes and from my experience they exist side by side just fine. Just add your socket.io server code to app.js to test it out and you can use the client side code within any of your express views.
This assumes you're using socket.io of course. I have no experience with other methods of using websockets with node.js.