Hi I looking for a documentation or example to connect to socket.io running on nodejs at server side from a pure JS from a client.
I have to remove the socket.io.js lib from the client side.
socket.io provides various transport layers. If you are happy to experiment and are sure that your client supports WebSocket in all cases, then you might be successful in reproducing the WebSocket-based part of the socket.io protocol on the client side. This, however, seems to be a tedious task compared to just using the code that you would re-invent (partly) anyway.
Use socket.io on the client side, or take an entirely different approach, also on the server side.
Related
I have the current APIs running in an express server along with MongoDB in form of HTTP requests response. I currently have the use case of a messaging system that I know requires web sockets.
Should I rewrite the whole APIs in socket.io? Or Is there any option to do it on top of the existing HTTP server
Any suggestions in this situation will be helpful.
No, the are not mutually exclusive. Keep using HTTP for things that make sense as APIs, and only add sockets for the things that require bi-directional messaging.
socket.io is not required, and it's usually better to just use plain websockets. socket.io is a old, large framework that's not needed.
I am looking to build an web application using node.js and possibly socket.io but I am having a lots of confusion regarding whether to use socket.io or go with plain http. In the app the node.js server will be basically an api server which serves json to the javascript client or may be mobile clients too. The web app will also has chat messeneger for its users, this is where socket.io comes in.
I am not sure whether to use socket.io for the whole app or only for the chat part. Although my app itself could benefit from socket.io but its nothing that I think can't be done using plain http and client making more requests to the server.
I have read at several places that sometimes socket.io can be difficult to scale for more users.
Socket.io often crashes and specially creates probs when there are firewall in clients system.
More importantly.....I checked out socket.io user list and did not find many users, so was curious to know what kind of platform is more know chat network like facebook messenger, google talk etc are built upon, Are any built using http-ajax and continues querying to the server.
Please help me out in solving this question. Some might argue that this is a opinion based question. But what actually I am trying to figure out the implementation of socket.io and its limitation.
I would suggest serving your API over HTTP and leave the real-time business to Socket.io. If you are adverse to using Websockets, like #GeoPheonix stated, you can choose from a variety of transport methods using both socket.io and sockjs (https://github.com/sockjs/sockjs-node).
As far as scaling is concerned, I deployed a socket.io based real-time analytics/tracking service for a very large application with ana average of 400+ concurrent connections with no visible performance impact, but this may depend on the implementation and hardware.
Socket.io is faster than plain http. I recommend you to use it for all since you have to have a chat in first place.
In my case, real-time Texas Hold'em-like game can receive up to 2500 concurrent with one node process. However, if you change transport from websocket to xhr-polling, It can receive like more 10x than pure websocket. Your application is just chat so, I guess a little slow down wouldn't be a problem. If you sure you will exceed this number, yes, scale socket.io is a pain.
This problem will happen only if you open socket.io for port other than 80 and 443. If you have frontend web server with other language already, you can still use socket.io on another subdomain to be able to run on port 80 without conflict with your main frontend web server. Socket.io support cross-domain without a problem.
Have you used trello.com? If not, try it :). It's best for task management or even some Agile thing. They used socket.io. https://c9.io/ is another one. It's online IDE with google doc-like collaborative. One thing to note is xhr-polling trasport in socket.io is the same with http-ajax with long-polling (Better than general ajax). You can read more info at:
http://book.mixu.net/node/ch13.html
Is there anyway to send data though sockets from Node.JS to SignalR? I have a Node.JS app that sends realtime information as JSON format. The other app it's an MVC C# app that uses SignalR to send the data to the client via socket. I want tosen data from de nodejs to signalr and signal send that info to the client.
You might consider better solution for internal communication between processes. SignalR is meant to be used between .Net server and client using different authentication, handshake, protocol and network layer methods, which is inefficient for internal server communication.
Take a look on ZeroMQ, is well simple and very easy to use tool, meant especially for such cases. It has bindings for most languages including .Net and node.js.
There is js client for browser to communicate with Signal R server.
http://www.nuget.org/packages/SignalR.Js
You probably can extract js file from it and run from Node.js.
And probably standard Socket.IO will just work, you need to subscribe to proper events and go.
If you want a node.js client for signalR that doesn't require jQuery I started this one. It intentionally only supports websockets.
https://npmjs.org/package/signalr-client
I am learning HTML5 and doing so by building a simple chatroom using Express, PassportJS, Mongoose/MongoDB, connect-mongoose, NowJS.
Everything works perfectly, except for one big problem: I am having trouble authenticating NowJS.
The usual way of doing this is to read the "this.user.cookie" property server-side and parse the string. However, for some reason, cookies is not being sent back to the server. (details here: NowJS cookie field in this.user is empty) After a lot of googling, I think there are no alternative, secured, way for me to authenticate NowJS connections/clients.
Question
I am thinking of stripping all of NowJS out of my web app, and using socket.io directly. Is socket.io easy with work with? Would I lose key functionality if I switch to socket.io, instead of using NowJS?
Can I use socket.io to:
1) Call server-side functions?
2) Share server-side variables with the client?
Socket.io does not share variables or allow you to call server side functions. It allows you to bind and emit events on the client side and server side.
As for your cookie not being sent, its most likely that its being considered a cors, cross domain request, this can happen if your using a different port for socket.io then the http server that set the cookie.
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.