I'm playing around with an open source project that uses Socket.IO to connect to the website chat.meatspac.es which is hosted on a different server. It connects like this
var socket = socketClient.connect('https://chat.meatspac.es');
And then it listens for the data that is also published on chat.meatspac.es. Does this only work because the chat.meatspac.es is also a Socket.IO application and it's emitting signals that can be picked up by this other open sourced project?
For example, I naively tried to connect to my Twitter stream
var socket = socketClient.connect('https://twitter.com/username');
but it wouldn't listen for messages published in my Twitter feed.
So, my question is, can Socket.IO only connect to servers that are emitting Socket.IO messages?
socket.io allows simulation of socket API (used in traditional desktop apps) for access with javascript (web).
But this is will not behave exactly as traditional sockets behave. It uses HTML5 websockets for sockets simulation
Sockets.io needs to have a compatible server app, that is shown here by deploying a server app using nodejs
Take a look at server side implementations of websockets today, socket.io with nodejs being one of them.
http://www.html5rocks.com/en/tutorials/websockets/basics/
So for your question using socket.io to create a socket connection to twitter:
var socket = socketClient.connect('https://twitter.com/username');
This is not possible because socket.io is not a real socket API, its just a simulation of sockets api using HTML5 websocket api and maybe other fallbacks (long polling, comet, etc). So the server should be compatible to handle the ws(websocket protocol) request and in case of twitter here to get feed stream, this is not the case so this can not be done like that.
See the twitter api to programmatically get access to twitter resources
https://dev.twitter.com/docs/api/1.1
Related
I'm trying to implement a web based chat program, my plan is to update an azure cosmos database with chat messages, then push an event to an azure event hub.
The missing element is for connected web browsers to receive these events.
I tried using the azure event hubs npm package (https://www.npmjs.com/package/#azure/event-hubs) but that looks like it's server side.
Is there a way to accomplish this without having to spin up some sort of server or service?
It sounds like you want to diectly connect EventHub via a browser with websocket, as I known, the only way to realize it is to use AMQP over WebSocket to connect EventHub.
There is a MSDN blog introduce this topic Connect to Azure Event Hub in browser ( using AMQP over WebSockets ), and the other blog of the same author introduce How to use AMQP protocol in Browser (JavaScript). And you can get rhea.js from its GitHub repo https://github.com/amqp/rhea/tree/master/dist.
Meanwhile, according to the information from the source codes of #azure/event-hubs, it seems to support the feature of AMQP over WebSocket in browser, as the figure below comes from the source code https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/eventhub/event-hubs/src/impl/eventHubClient.ts#L259.
And there is a sample code of websockets.ts for EventHubs, and it requires #azure/event-hubs version next in its package.json. I think you just need to use WebSocket in browser instead of WebSocket from import WebSocket from "ws"; in the sample, then you could make it works in browser.
I am trying to develop a flutter chat app using nodejs and socketio.i'm just getting started with the socketio i have surf several examples in which every front end or client side having a set of socketio script. Can i develop my code purely server side? so that i can integrate with any type of front end.
You can do that. Socket.io is a web socket implementation in node js. It enables real-time, bidirectional and event-based communication between client and server.
Server and client can send and receive the events. If you don't want write any script in client side then you don't have any use of sockets.
Edit:
socket.io given nice example for chat application with explanation. https://socket.io/get-started/chat/
Socket.io has two distinct parts - the server and the client. The docs make this clear. There is nothing preventing you from just writing the server part, and leaving the client implementation out of the equation, for someone else to implement.
Although the main point of Socket.io is to implement the WebSocket protocol, it does so by wrapping it in its own interface, so to speak. So a socket.io server can only talk to socket.io clients, not clients that implement WebSocket in other ways. That being said, there are socket.io client libraries for pretty much every major language out there:
Javascript (main client)
Java
C++
Dart/Flutter
You also asked about React and Angular, but both of those are web front-ends, so there should be no reason why they can't use the standard Javascript client library with those frameworks.
i would like to know if it is possible to have socket.io featured client website to send message to winsock c++ server application?
My current project involve controlling a robot using c++ application and i have design a simple local host website.
i would like to have a web page as user interface (client) and my c++ application (server) that will accept connection from client and listen to the port for incoming messages. ( which mean socket.io interacting with winsock through IP)
I have a working C++ winsock client/server application that are able to communicate between each other using winsock. Besides that, i have play around with the socket.io demo chat from this webpage http://socket.io/get-started/chat/
If so, is there any good tutorial or guideline out there that capable of having the sockets interaction? i have no luck finding one.
Thanks
I'm creating an app where the server and the clients will run on the same local network. Is it possible to use web sockets, or rather more specifically, socket.io to have one central server and many clients that are running native apps
? The way I understand socket.io to work is that the clients read the web-pages that are served from the server but what happens when your clients become tablet devices running native apps instead of web pages in a browser?
The scenario I'm working with at the minute will have one central server containing a MEAN app and the clients (iPads) will make GET requests to the data available on the server. However, I'd also like there to be real-time functionality so if someone triggers a POST request on their iPad, the server acknowledges it and displays it in the server's client-side. The iPad apps will (ideally) be running native phonegap applications rather than accessing 192.168.1.1:9000 from their browser.
Is this technically possible to connect to the socket server from the native apps or would the devices have to send POST requests to a central server that's constantly listening for new 'messages'? I'm totally new to the whole real-time stuff so I'm just trying to wrap my head around it all.
Apologies if this isn't totally clear, it's a bit hard to describe with just text but I think you get the idea?
Correct me if I am wrong.
You have multiple iPads running native app. They send a POST request to your node JS server which is running in a computer in the same local network. Whenever the server receives a request from app, you want to display that a request has been received in your computer screen.
If my assumptions about the scenario is correct, then it is fairly easy to do. Here are the steps to do it.
Create a small webpage (front end). Load socket IO in the front end page like this -
<script type="text/javascript" src="YOUR_SERVER_IP/socket.io/socket.io.js"></script>
Then connect to server using var socket = io(). This should trigger connection event in your backend.
Handle all POST request from apps normally. Nothing special. Just add a small snippet in between. socket.emit('new_request', request_data). This sends new_request event to front end.
Handle the new_request in your front end using socket.on('new_request', function(request_data) { ... });. That's it. No need to add anything to your native app for realtime update.
The second step would be a little complicated as it is necessary to make socket variable available inside all POST requests. Since you chose node.js, I don't think you need any help with that.
Not totally clear on your project, but I'll try to give you some pointers.
An effective way to send data between native apps and a server is using a REST server. REST is based on HTTP requests and allows you to modify data on the server, which can connect to your database. The data returned is typically either JSON or XML formatted. See here for a brief intro: http://www.infoq.com/articles/rest-introduction
Android/iOS/etc have built in APIs for making HTTP requests. Your native app would send a request to the server, parse the response, and update your native UI accordingly. The same server can be used from a website using jQuery ajax HTTP requests.
Express.js is more suited to serving web pages and includes things like templating. Look into "restify" (see here: mcavage.me/node-restify/) if you just want to have a REST server that handles requests. Both run on top of node.js (nodejs.org).
As far as real-time communication, if you're developing for iOS look into APNS (Apple Push Notification Service). Apple maintains a persistent connection, and by going through their servers you can easily send messages to your app. The equivalent of this on Android is GCM (Google Cloud Messaging).
You can also do sockets directly if that's easier for you. Be careful with maintaining an open socket on a mobile device though, it can be a huge battery drain. Here's a library for connecting ObjC to Socket.IO using websockets, it may be useful for you: https://github.com/pkyeck/socket.IO-objc
Hope that helps!
To answer your question, it is definitely possible. Socket.io would serve as the central server that can essentially emit messages to all of the client. You can also make Socket.io listen for the messages from any of the clients and serve the emitted message to the rest of the clients.
Here's an example of how socket.io can be used. Simply clone, npm install, and run using 'node app.js'
All you have to do is to provide a valid server address when you connect your socket from the iPad clients:
var socket = io.connect( 'http://my.external.nodejs.server' );
Let us know if you need help with actual sending/receiving of socket events.
It is possible to connect to Websockets from your apps.
If you are using PhoneGap then you need a pluging that gives support to websockets in your app (the client) and then use websocket like normal way using Javascript see this.
If your app is native iOS look into this it could help you.
The primary use of the Sockets in your case is to be a bidirectional "pipe" between an app and server. There is no need of server sending the whole web-page to the native app. All what you need is to send some data from server to the client(app) in response to POST (or GET) request and then using this data on client side to update client's UI in real-time. If you are going to use moderate amount of devices (say tens of them), you may have connected all of them to the server permanently keeping individual socket connection open for every individual link server-to-app. Thus you may deliver data and update client's state in real time.
In fact web browsers also employ sockets to communicate to web servers. However as in general case there is no control on amount of concurrent clients in Internet, for the sake of limited networking resources conservation, servers do not keep sockets open for a long time, closing it just after the web-page was sent to client (or timeout has expired). That's how HTTP protocol works on the low level. The server waiting for the HTTP clients (browsers) by listening the 80 port, responding them by sending the whole web page content, then closing the connection and keep waiting for another requests on the same port.
In your case it's basically a good idea to use socket.io as it's a uniform implementation of sockets (ok WebSockets) on both client and server side. The good starting point is here
I'm looking to have a video conference website running on node.js + express.js instead of regular apache and I'm having trouble deciding on a solution.
I need the server to send the website to the user through express.js, plus, connect people in a queue so they can enter a video conference with strangers.
Should I build two different server applications, one for the express.js and one for the webRTC server, listening on different ports?
If so, how can I make the user interact with the different aplications? They will need to be able to login, be placed in the queue and be able to see the strangers once the connection is established.
WebRTC and Express.js is differ ExpressJS (Web frame work mapping your request)
but WebRTC is differ(Peer-to-Peer) communication with the help of signalling means exchange information about two browser so you can use Socket.IO or any other websocket framework
Every thing depend of signalling you want to connect particular person send signalling that particular person its not possible in Express.js so use any websocket framework like socket.io