I am working on chat server so I want to create a server and I have been said to use express and socket.io module. Would someone explain me about these modules and help me making chat server?
When you post questions on Stackoverflow, it is expected that you provide some code that you have experimented with so far. Please refer here for details about how to ask a question.
However, from the looks of it, you seem to be someone who is just starting off with Socket.io and NodeJS. So I'm answering here so that someone else who might also be at your stage can get an idea where to start.
A good starting point for learning how to build Chat applications with Socket.io and NodeJS using Express can be found here on Socket.io's official website
Scotch.io also provides a good tutorial on this here
In a chat application, Socket.io provides an abstraction over the HTML5 WebSockets API on the client side, and implements WebSockets on the server side, where your server is running on NodeJS.
ExpressJS is a Web Framework built on top of Node, that provides you an easier API for building servers, and dealing with requests.
Related
I am preparing to build a WebSockets system to have a bidirectional communication from my server to my clients through WebSockets.
I know that Laravel now very well supports 3rd parties like Pusher Channels and Ably.
There are also some other ways that are also very convenient and simple to use such as Laravel Websockets, soketi, laravel-echo-server.
But my problem is client-side cannot include 3rd party Client Library. My client-side is a Cross-platform Game based on Javascript and HTML5. I can only connect client-side to server-side through WebSocket.
As far as I know, when using 3rd party for server-side, I should use their JS Client Library like pusher/pusher-js, laravel/echo ... Therefore, I can't find any documents if I want to use them with WebSocket.
My goal is to find the best and most suitable solution for both client and server side.
What I have tried?
IDEA 1: Convert pusher.js to my own js
I spent 2 weeks on this. I see this as possible and some functions might work. However, it will take a long time if I want to convert the whole thing.
IDEA 2: Using Pusher and connect the client via Pusher Channels Protocol
I have tested them as follows
var socket = new WebSocket('ws://ws-[cluster_name].pusher.com:[port]/app/[key]');
It worked. I can see them connected on the Pusher Debug Console. However, I can't find any documentation regarding the basics like Subcribe channel, Listening events, Send message to other client, Ping, Pong, ...
IDEA 3: Using Laravel Websockets
Like idea 2, I couldn't find any documentation or examples.
IDEA 4: Using NodeJS instead of Laravel. Choose ws packages
I tried it and it worked as expected. WS is really simple but it is exactly what I want. However I don't have many years of NodeJS experience. Therefore, I feel there are many risks if I choose it to build a new project.
Could you tell me a best way to deal with this problem?
Thanks
The Pusher and Laravel Echo JavaScript clients work with any Pusher-compatible websockets host. (Pusher uses websockets, too.)
All it takes is a little configuration; see, for example, Laravel Websockets' guide on configuring Laravel and then configuring Echo. Both steps point your Pusher requests at your chosen Pusher replacement instead.
No need to write your own library or manually consume websocket data.
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 am aiming to create a WebRTC chat (video/audio) application and most of tutorials and demos that I see are using the following signaling channel:
signaling.simplewebrtc.com:8888
I even found this great demo, where the developer stated that it does not depend on this signaling channel, but when I went through the code I found it there.
Can someone explain me, how can I substitute this with my own signaling channel?
I do not completely understand your question. I guess the URL you provided points to an websocket server. Websockets are often used for signaling because they provide a permanent, full-duplex connection (this means that the server is able to push messages to the client without an previous request).
You have to exchange network information between the two parties who want to set up an RTCPeerConnection because of NAT and firewalls etc... How to exchange that information is not part of the WebRTC-specification. You can use any protocol you want, HTTP,Websockets, even EMail (but that would be pretty ugly to implement :) ). But if you want to build your own signaling-server using node.js you can have a look at the tutorial I am currently writing. It explains in detail how to setup your own very simple video-chat using WebRTC and a Node-Server hosted on uberspace.de:
Tutorial: Create your own Videochat-Application with HTML and JavaScript
If you use my tutorial it would be great if you could tell me if it is understandable.
Edit:
As I am still getting requests for this old tutorial, please use an up to date one like those:
https://www.baeldung.com/webrtc
https://www.html5rocks.com/en/tutorials/webrtc/basics/
Please take a look at this excellent blog on the signaling options that are available for WebRTC.
I have listed a few important blogs and sample WebRTC applications that you might also want to review to help you build your chat application.
I installed nodejs from Install NodeJS along with the required dependencies at signalmaster
Ran node server.js in cmd.
And server started running.
P S: Change url option present in simplewebrtc.bundle.js
Let me know if you face any problem
I wonder why no one has mentioned this so far . You can also use the sip framework based webrtc libraries and clients such as sipml5 , jssip etc . Additionally since you mentioned you would like your own server setup to cater to signalling requests , you will have a wide variety of websockets based sip servers to choose from such as officesip , kamailio , mobicents etc .
You can try and modify the the latest application that ships with Mobicents at https://code.google.com/p/sipservlets/wiki/HTML5WebRTCVideoApplication that allows you to chat and video chat.
When using web sockets all the tutorials I can find talk about the code for the client side. But the server side is just left out. What does the connection url here actually point too? Do I need to also be using PHP, Ruby, node.js or any server side language?
var connection = new WebSocket('ws://html5rocks.websocket.org/echo', ['soap', 'xmpp']);
Tutorial referenced:
http://www.html5rocks.com/en/tutorials/websockets/basics/
There are some server side languages that have Websockets support, I personally recommend using:
Socket.io
Who works over node.js, it's very easy to setup and a good starting point. Later you can have an Websockets endpoint in any language. Java and C# solutions are a bit complicated by the time.
Yes, you need a server that handles websockets. Many do including Apache HTTPD, Apache Tomcat, Play framework, and nodejs.
Here is an example:
http://www.tomcatexpert.com/blog/2012/05/01/how-apache-tomcat-implemented-websocket
Have you seen the great (and simple) echo sample on websocket.org?
Also, Kaazing has a hosted WebSocket server, and a browser-based tutorial that walks you through a simple pub-sub example.
Check out:
Tutorial Home Page with screencast of completed app
Seven-part blog post about with step-by-step instructions
Completed demo in JSFiddle (with HTML and JavaScript source code)
Hint: Open this link in two browser windows an interact with the slider above the image
Hope this helps!
There is a server I need to talk to that publishes a protocol over TCP/IP for querying data from a database and listening on a socket to receive notifications when data is updated. The sever guys provide a Java API which uses this TCP protocol. This means I could easily write a Swing App to talk to this server.
I would like a browser based solution. As the protocol is known to me, could I do this in JavaScript? My app will have to display the data in a table. I have heard of Web Sockets but I'm not sure if it will allow this two way communication. Is it feasible? Is there a better way that is cross platform and will work in most browsers? Should I be considering a Java Swing based solution that runs inside a browser?
EDIT: What about changing the code in my C++ server to add an additional interface that my Javascript code can communicate directly with it?
The WebSocket protocol differs from TCP/IP sockets. You will have to write something to link them together.
You can do this perfectly well in JavaScript: use Node.js. There's enough tutorials to be found on the subject. The best way to link it to your in-browser JS is through Socket.IO.
Create a Node.js server that connects to the api
Make the server talk to your web app
Use it :)
This will work cross-platform and cross-browser (Socket.IO can use/emulate websockets even on IE6(!!)). You'll have to run a server-app (the Node.js app) though.
My personal opinion is that if you want a web/browser based solution, you should use native technology, and not Java.
Hope this helps :)