HTML5 web sockets provides stable connectivity to servers. By using these web sockets we can setup a stable connection between browser and sever, and then we can send or receive messages.

Like shown in below image, users send and receive messages on real time

Observe below GIF, One is chrome and another is firefox, Whatever we type in chrome, that will be displayed in firefox.

Lets write java program for sharing editor

Java Program

To run below program, you need add java_websocket dependency. Here it is the maven dependency xml.

Once you install the above dependencies, run below program
import java.util.HashSet;
import java.util.Set;

import org.java_websocket.WebSocket;
import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;

public class App extends WebSocketServer {

    private static int TCP_PORT = 4444;
    private String value = "";

    private Set<WebSocket> conns;

    public App() {
        super(new InetSocketAddress(TCP_PORT));
        conns = new HashSet<WebSocket>();

    public void onOpen(WebSocket conn, ClientHandshake handshake) {
        System.out.println("New connection from " + conn.getRemoteSocketAddress().getAddress().getHostAddress());

    public void onClose(WebSocket conn, int code, String reason, boolean remote) {
        System.out.println("Closed connection to " + conn.getRemoteSocketAddress().getAddress().getHostAddress());

    public void onMessage(WebSocket conn, String message) {
        System.out.println("Message from client: " + message);
        value = message;
        for (WebSocket sock : conns) {

    public void onError(WebSocket conn, Exception ex) {
        if (conn != null) {
            // do some thing if required
        System.out.println("ERROR from " + conn.getRemoteSocketAddress().getAddress().getHostAddress());
    public static void main(String[] args) {
        new App().start();

HTML Code 

This code contains textarea element. Whatever user types in that textarea, it will be sent to java web socket server. Java server will send that message to all its connections. That is how one user's text will be shown to all users. 
<!DOCTYPE html>
        .layout {
        textarea {
            border:1px solid #ccc;
        var ws = new WebSocket("ws://");
        var elm = document.getElementById('myTextArea');
        ws.onopen = function() {
        ws.onmessage = function (evt) {
            myTextArea.value =;
        ws.onclose = function() {
        ws.onerror = function(err) {
            alert("Error: " + err);
        function share(event) {
       <div class="layout">
        <h1>Sharing editor</h1> 
        <textarea id="myTextArea" onkeyup="share(event)" rows="100" cols="50"></textarea>


  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

  2. Very useful and interesting content.

    Quickbooks Expert
    quickbooks support phone number

  3. It provides stable connectivity to servers!
    yahoo mail sign up new user

  4. If any page has quality posts like yours then I will search for information very quickly. Please donate again
    ludo king

  5. This comment has been removed by the author.

  6. Thanks for your great and helpful presentation I like your good service. I always appreciate your post. That is very interesting I love reading and I am always searching for informative information like this.iot training institutes in chennai | industrial iot training chennai | iot certification chennai | iot training courses in chennai

  7. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
    Check out : machine learning tution in chennai
    artificial intelligence and machine learning course in chennai
    best training insitute for machine learning

  8. Just seen your Article, it amazed me and surpised me with god thoughts that eveyone will benefit from it. It is really a very informative post for all those budding entreprenuers planning to take advantage of post for business expansions. You always share such a wonderful articlewhich helps us to gain knowledge .Thanks for sharing such a wonderful article, It will be deinitely helpful and fruitful article.

  9. Buat kalian pemain pemula atau profesional tentunya membutuhkan teknik yang pas untuk menang dalam permainan AduQ Online
    bandar ceme terpercaya
    paito warna
    forum prediksi

  10. Really informative article.Really looking forward to read more. Really Cool.
    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร สล็อตออนไลน์ กับทางทีมงานของเราเพียงเท่านั้น
    สมัครสล็อตออนไลน์ >>> Goldenslot
    สนใจร่วมสนุกกับ คาสิโนออนไลน์ คลิ๊กได้เลย
    มีทั้งคาสิโนออนไลน์ หวยออนไลน์ ฟุตบอลออนไลน์ สล็อตออนไลน์ และอื่นๆอีกมากมาย

  11. Great. It is good to constantly coming up with creative ideas. Provides much needed knowledge. goal oriented blog posts and always tried to find creative ways to meet goals.

    Online affiliates

  12. AppVN is a third-party app store for Android. Unlike Google Play, this app store provides you with some unique features, such as the facility to download certain official premium apps for free.
    Appvn APK
    appvn ios
    appvn apk download


  13. Your post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
    what is seo
    types of seo

  14. This is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
    Android Application development
    Web application


  15. Get the most advanced Hadoop Course by Professional expert. Just attend a FREE Demo session.
    call us @ 9884412301 | 9600112302
    Hadoop training in chennai | Hadoop training in velachery

  16. Nice Post...I have learn some new information.thanks for sharing.
    Data Analytics Courses in Mumbai

  17. I`m working at html5 app development firm and it will surely help me out in my projects.

  18. This is a wonderful article, Given so much info in it, Thanks for sharing. CodeGnan offers courses in new technologies and makes sure students understand the flow of work from each and every perspective in a Real-Time environmen python training in vijayawada. , data scince training in vijayawada . , java training in vijayawada. ,

  19. The information you have posted is very useful. The sites you have referred was good. Thanks for sharing real time sharing editor using Java web sockets.
    Minneapolis Web Design

  20. Best Fish Finders For The Money 2020 – Cheap & Budget Friendly
    Garmin Striker 4 Built-in GPS Fish Finder is found to be one of the best fish finder brand GPS. It’s comparatively small with other fish finders but still, it does its job perfectly. Each and everything will be clear to you due to its high colour contrasts and brightness. The good thing about it is you can mark your hot spots to make fish catching easier for you regardless of whether you are in open water or in the lake.

  21. Best Water Based Polyurethane For Floors 2020
    Bona Mega Wood Floor Finish is a floor finish specially designed for wood floors. RUST-OLEUM Varathane Enhancing the natural beauty of the floor and retaining its original color, it provides maximum shine and makes your floor look good as new. This is a clear liquid that gives extra-ordinary clean and clear finish to the floors leaving it bright and sparkly.

  22. Best Spray Tan Solution 2020
    A best spray tan solution is a method of giving you tanned skin for several days, without having to reveal yourself to deadly UV light as you would in a tanning salon or by sunbathing. There are several primary qualities that a tanning solution should have so that you attain natural-looking coverage and a great tanned color that not only shines up your complexion but also persists a pretty long time.Sunless tanners are available in lotion, gel, spray, powder, and mousse. There are also staged tanners for deeper and longer-lasting results.

  23. Best 6 Volt Golf Cart Batteries In 2020
    Batteries are what powers the whole circuit process and are absolutely crucial for the machine; therefore you cannot risk getting a battery for your cart that Is undependable and erratic.Your golf cart is very essential because it is a mode of transportation, which is indeed, If not, the most revolutionary invention of mankind, providing all sorts of benefits including its efficiency and how less time consuming it makes our travels or journeys, and It does so with quite the comfort and ease.

  24. This is also a very good post which I really enjoyed reading. It is not every day that I have the possibility to see something like this .. what is cbd

  25. A great piece of writing! You have an efficient flair for high quality writing. I am highly impressed by your way of writing this content beyond words.
    SAP training in Kolkata
    Best SAP training in Kolkata
    SAP training institute in Kolkata

  26. I really have a lot of appreciation for your writing. Thank you so much for all your priceless input on this topic.
    SAP training in Mumbai
    Best SAP training in Mumbai
    SAP training institute Mumbai

  27. Great post. I have learned a lot. Thanks.
    There are some discount drapes. beautiful indoor curtains, please try that.

  28. I would like to say thank you for sharing the Informative article, this is a very Informative
    article about deep learning. You are doing a great job, keep it up.

  29. I visited your site for the first time and started reading this one blog. It kept me stuck to your content. You have written it so well that I can’t keep my eyes off from it and reached the end of this.
    Explore the fashion

  30. Really awesome blog to visit
    Like it so much
    Keep it up

  31. i am very impres of your post.

  32. Hello very nice work

  33. Great post. I have learned a lot. Thanks.
    This will be very helpful for my Digital marketing blog

  34. Hi I like your blog. There is a lot of good information on this blog, I loved reading it and I think people will get a lot of support from this blog
    Digital exhibition
    Online trade fair
    online events
    digital events
    digital trade fair
    Upcoming Online events
    upcoming exhibitions
    Explore Best Online Events

  35. Real time sharing editor using Java web sockets. Your article is fascinating and tell you what? I have bookmarked your site and even shared to my friends. Thank you.
    I know of a school & fashion house that has a good education in fashion. Fashion training schools in accra Riohs Originate is a Creative Art Service and Training Institute in Ghana.
    They provide services and training for individuals/organizations that value their image, style, color and insist on promptness, accuracy and consistency.
    best fashion schools in accra ghana
    top fashion schools in accra

    fashion training schools in accra

    names of fashion schools in accra

    fashion design schools in accra ghana

  36. I must thank you for the efforts you have put in writing this blog. I am hoping to check out the same high-grade content by you in the future as well.
    I was very pleased to uncover this website. I want to to thank you for your time for this fantastic read!! I definitely savored every little bit of it and i also have you saved as a favorite to see new things in your site.

    No more waste time to searching #HDimages, #PCwallpaper, #smartphone_wallpaper, #socialmedia_banner, #socialmedia_image_post, #natureHDimages, and many more awesome pictures. Just visit All Awesome Pictures Only For Love Hearts and choose your best choice.
    All Awesome Pictures Only For Love Hearts
    All Awesome Pictures Only For Love Hearts
    All Awesome Pictures Only For Love Hearts

  37. This is the information exactly what I am looking on internet today. i learned useful information from this post. article is nicely explained and easy to understand. thanks for sharing this valuable information with us. keep your good work.

  38. inhostpk Offers a variety of hosting services, from advanced VPS, Business hosting plans to beginners who want to start using shared hosting.
    Visit us 👉

  39. Army of people additionally are getting a charge out of city Matka in Satta Bazar. We've a twisted to feel pleasant acquainting your outfitted with carry the quick and awesome outcomes to you. Satta fix jodi Do I wish to learn out the outcomes at that point escort the decision of discovering the official site? you'll have the option to check here the snappier outcomes than the other Matka site with free SattaMatka fortunate.



Follow this blog by Email

Popular Posts