AndroidでWebSocket通信するサンプルです。 使用したライブラリは TooTallNate/Java-WebSocket · GitHub です。 weberknecht - Java WebSocket Client Library - Google Project Hosting のほうが人気があるらしいですけど、Java-WebSocketのほうがライセンス緩かったので… WebSocketのサーバー側はテキトーに準備しておいてください。 自分は igrigorik/em-websocket · GitHub を使いました。 Android側は次のような感じになります。 public class MainActivity extends Activity { private static final String TAG = "MainActivity"; private
サーバー側を実装するには? サーバー側を実装するには?解説 サーバー側を実装する場合、通常、ウェブサーバーや、フレームワーク、ライブラリ等による通信プロトコルの実装を利用して開発を行います。 ここでは、JavaのサーブレットコンテナであるJetty 8 での実装を例に説明を行います。サーバー側のAPIに関しては共通の規約は存在しませんが、イベント駆動モデルで実装がされている場合は、クライアント側とほぼ共通するイベントに対してコールバック関数を定義するという点で、それほど大きな違いはありません。 実装によっては、Jettyのようなイベント駆動モデルの抽象化がされておらず、通信プロトコルの生データに近いレベルを取り扱わなければならない場合がありますが、この記事の範囲を超えますので詳細には触れません。 Jetty 8 での実装では、org.eclipse.jetty.websocket.WebS
皆さん! Pingフレーム送ってますか? WebSocketは、無通信状態が続くと勝手に切断されちゃうことがあるので、Ping/Pongフレームは結構大切ですよ! Pingフレームは双方向のハートビートに、Pongフレームは一方向のハートビートに使えます。 相手に鼓動が届くなんて、ロマンティックですね。 そして、Jettyさんの話。 WebSocketプロトコルにはドラフト版からRFC版までいくつかのバージョンがあります。 多くのWebSocketのライブラリは、バージョンが固定だったり、起動時にバージョンを指定するようになっています。 接続してくるクライアントのWebSocketのバージョンに合わせて、処理を切り替えることのできるサーバは少ないのですが、そのうちのひとつがJettyなんです。 Jettyさんは、バージョンの差異をラップし、sendMessageメソッドやcloseメソッド
以下、Jetty 8.1.4.v20120524の話。 JettyでWebSocketサーバを実装する場合、WebSocketServletはWebSocketインターフェースを具象化したクラスを返す必要がある。 また、JettyをWebSocketクライアントとして使った場合もWebSocketインターフェースを使う。 さらに、WebSocketインターフェースは、OnFrame・OnControl・OnTextMessage・OnBinaryMessageの4つのインターフェースに派生する。 WebSocketインターフェースは以下の2つの抽象メソッドを持つ。 // WebSocket void onOpen(Connection connection); void onClose(int closeCode, String message);
Introducing WebSockets - Bringing Sockets to the Web Stay organized with collections Save and categorize content based on your preferences. The problem: Low latency client-server and server-client connections The web has been largely built around the so-called request/response paradigm of HTTP. A client loads up a web page and then nothing happens until the user clicks onto the next page. Around 2
クライアント側の送受信の処理を実装するには? クライアント側の送受信の処理を実装するには?解説 クライアント側の実装は、WebSocketオブジェクトを利用します。 WebSocketオブジェクトはコンストラクター「WebSocket(url,[protocol])」でインスタンス化します。引数urlは接続先のurlで通常は「ws://」スキーム、暗号化されたセキュアな通信の場合は「wss://」スキームで始まる文字列です。 サーバーからのデータの受信はonmessageイベントハンドラを実装します。送信されてきたデータはハンドラのevent引数のdata属性で取得します。 サーバーへのデータの送信は「send(data)」メソッドを使用します。「send(data)」の呼び出しは、データを送信待ち行列に追加し、送信の完了や応答は待ちません。 // infoは情報表示用のdiv要素 var
WebSocket on Jetty 8 (OnBinaryMessage) and getUserMedia on Google Chrome WebSocket on Jetty 8 and getUserMedia on Google Chrome Jetty 8.1.4 と Google Chrome で WebSocket を使って USB カメラ (Web カメラ) の映像をバイナリデータとして送受信をしてみます。 いわゆる WebRTC というらしいです。 前準備 通常版の Chrome でも getUserMedia の機能が実装されていますが、ここでは dev channel をインストールしてみます。 Fedora 17 (x86_64) の場合は、http://dev.chromium.org/getting-involved/dev-channel の 64-bi
Firefox11になってとっくにWebSocketのベンダープレフィックスとれてたし、 バイナリデータの送受信の辺りがどうなってるか確認してみた。 確認したブラウザはFirefox11.0とGoogle Chrome18.0.1025.162。 サーバ側 node.jsで実装する。 httpサーバ用にconnectを使って、WebSocketサーバはWebSocket-Nodeを使う。 それぞれnpm install connect、npm install websocketでモジュール入れる。 サーバ側のコードは次の通り。 // http server var connect = require('connect'); var httpServer = connect() .use(connect.static(__dirname + '/webroot')) .listen(1234
長い記事なので、先に結論だけ書いておきます。WebSocketのバイナリメッセージ機能は、これまでのインターネットのあり方をひっくり返します。「そんなの知ってるよ」という方もいるとは思います。僕も理屈では分かってたつもりだけど、実際にアプリを作ってみて、具体的にそれを感じることができたので、ちょっと長いですがどういうことなのか説明してみます。 WebSocketとは # WebSocketは、HTML5関連の中でも特に注目を集めている技術の一つです。通常のHTTP通信であればクライアントからのリクエストなしにサーバーは応答しませんが、WebSocketを使うことでクライアントとサーバーの間で双方向の通信が可能となります。これを利用することで、今後様々なリアルタイム性の高いサービスを構築することが可能になるでしょう。 そんなWebSocketですが、これまで波乱の道を歩んできました。数年前か
http://tily.no.de/telephone トップページ、部屋とニックネームを決めて開始する http://tily.no.de/telephone/sandbox 手軽に試す用 電話というか音声チャットなんだけど、Flash のマイクでとった音声を WebSocket 経由で送信して、受け取った側では Web Audio API とか Audio Data API とかで再生するというのを作った。Firefox と Chrome で動く。 はずなんだけど、no.de の SmartMachine のスペックが低いせいか、遅延のあるせいか相手側の音声がブツブツ切れて聴こえてしまう…。ローカルではちゃんと音声チャットっぽいことができているんだけど。 なんか色々他の人のコードを使ったり参考にしたりしたので書いておきます。 socket.io サンプルのチャットプログラム デザインと
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く