thaibinhindex / websockets-log-tail

Follow a stream (like a log file) from a server in the browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

websockets-log-tail

Follow a stream from a server in an HTML5 compatible browser (like tailing a log file).

Status: beta

This project holds demonstration java source code that uses websockets to send a sample stream of 10 lines of text a second to a browser.

While viewing the web page scroll to the bottom happens automatically but can be paused by hitting the space bar. Auto scrolling is resumed by hitting the space bar again.

Run the demo

git clone https://github.com/davidmoten/websockets-log-tail.git
cd websockets-log-tail
mvn test jetty:run

Go to http://localhost:8080

or to view a tail of /var/log/syslog: http://localhost:8080/?tail=true.

Technical details

This demo has dependencies on RxJava 2.x, jetty-websocket and jetty-server artifacts and their dependencies. RxJava is a great addition to a streaming solution because it simplifies cancelling subscriptions and enables functional transformations (and all the other superb RxJava goodness like retries, timeouts, caching, multicast, and a heap more).

The code in this project is super simple and brief thanks to jetty libraries.

  • index.html - calls ViewerServlet as an html5 websocket service
  • web.xml - defines url for ViewerServlet
  • ViewerServlet - implements jetty WebSocketServlet.doWebSocketConnect() and returns a StreamWebSocket
  • StreamWebSocket - implements jetty WebSocket, starts and stops streaming to browser

About

Follow a stream (like a log file) from a server in the browser.

License:Apache License 2.0


Languages

Language:Java 77.7%Language:HTML 22.3%