📜 ⬆️ ⬇️

Gif sockets. Real-time communication via animated GIF

It is not known that Alvaro Videla, a developer from VMware, smoked, but the gifsockets library he created was clearly supposed to be released on April 1, not today. This is a library for setting up a realtime communication channel, using animated GIF as a transport!

The idea is that in the format of an animated GIF, the number of frames is not indicated, so after displaying the picture, the browser waits for new frames from the server until it receives signal bits about the end of the file. In other words, the server can push messages to the browser over an open channel in the GIF. Everything is very simple.

It is difficult to find this technology a useful application, but the author has several ideas: for example, an interactive progress bar to display the progress of a task on the server. In addition, such “Websockets of the 90s” work in any browser, even in IE6, that is, if a client requires support for real-time communications in ___ browsers, even the most ancient, you can offer him such an option, jokingly or seriously.

In addition, such gifs can be adapted for server load indicators, online chats, interactive maps, weather widgets, temperature, etc., displaying the number of users on the site.
')
Translation in GIF text messages from the server
Here's how the channel is established and messages are sent from the server (Clojure REPL)
;; in the repl do the following to import the libs (use 'gifsockets.core) (use 'gifsockets.server) ;; ;;Then we declare the tcp server (def server (tcp-server :port 8081 :handler gif-handler)) (start2 server) ;; wait for a browser connection on port 8081 ;; go and open http://localhost:8081/ in Safari or IE6 ;; In Chrome it works a bit laggy and in Firefox it doesn't work at all ;; ;; Now let's create the gif encoder that we use to write messages to the browser. (def encoder (create-gif (.getOutputStream client))) ;; ;;Now we are ready to send messages to that browser client (add-message encoder "Hello gif-sockets") ;; now you should see a GIF image with the new message on it. (add-message encoder "Zup zup zup") (add-message encoder "And so forth") ;; ;; Now let's clean up and close the connection (.finish encoder) (.close client) 

Video


PS In the discussion on Hacker News , they remembered that this hack with the update of the “infinite” gif was shown back in 1999 .

Source: https://habr.com/ru/post/151538/


All Articles