GIFソケット。 アニメーションGIFを介したリアルタイム通信

VMwareの開発者Alvaro Videlaが喫煙したことは知られていませんが、彼が作成しgifsocketsライブラリは、今日ではなく4月1日にリリースされること明らかでした。 これは、アニメーションGIFをトランスポートとして使用して、リアルタイム通信チャネルをセットアップするためのライブラリです!



フレームの数はアニメーションGIFの形式では示されないため、画像を表示した後、ブラウザはファイルの終わりに関する信号ビットを受信するまでサーバーからの新しいフレームを待ちます。 つまり、サーバーは、GIFの開いているチャネルを介してブラウザーにメッセージをプッシュできます。 すべてが非常に簡単です。



この技術を有用なアプリケーションとすることは困難ですが、著者にはいくつかのアイデアがあります。たとえば、サーバー上のタスクの進行状況を表示するインタラクティブな進行状況バーです。 さらに、このような「90年代のWebsocket」は、IE6でもすべてのブラウザーで機能します。つまり、クライアントが_all_ブラウザー(最も古いブラウザーでも)でリアルタイムの通信サポートを必要とする場合は、楽しくまたは真剣にこのオプションを提供できます。



さらに、このようなgifは、サーバー負荷インジケーター、オンラインチャット、インタラクティブマップ、天気、気温などのウィジェットに適用でき、サイト上のユーザー数を表示できます。



サーバーからGIFテキストメッセージでブロードキャストする
チャンネルを設定し、サーバー側からメッセージを送信する方法は次のとおりです(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)
      
      





映像





PS Hacker News議論では、「エンドレス」GIFの更新を伴うこのハックが1999年実証されたことを思い出しました。



All Articles