Coder Social home page Coder Social logo

websocket-demo's Introduction

WebSocket Demo

This is a basic example of WebSocket pushes the server’s time to all connected clients.

Server

The endpoint Service ("/ data") schedules the task and publishes the server time to the connected clients. The timer is implemented as lazy. So the timer is scheduled when the first client connects to the endpoint. After that, the message is sent by async to all the clients connected to every minute interval.

Client

The Web client is pretty simple. On the page load, the JavaScript code connects to the WebSocket endpoint on the server. The callback onMessage() is invoked when the message (server's time) arrives. In this callback, the current time is updated in UI. Here there is no page refresh, no heavy HTTP headers and, no AJAX long polling hacks either.

How to test?

  1. Run Driver.java.
  2. Enter http://localhost:8080 on your browser.

websocket-demo's People

Contributors

ran-jit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.