Union Platform(6) Union Server入門
本エントリーではUnion Serverに焦点を合わせます。UnionのバージョンはUnion alpha3を使用します。
Union Serverはtryunion.comを利用して試すことが出来ますが、ローカルにもUnion Serverをインストールすることで快適な開発環境を整備しましょう。
システム要件
System Requirementsに記載されています。JAVAの実行環境があれば、大抵は動くと思います。
Union Serverのインストール
Union ServerはJAVAの実行環境があれば、実行出来ます。Windows、Mac OS X、各種Linuxへインストールが可能です。
Union Serverを実際にインストールして、管理ツールから接続を確認してみましょう。
- Union Serverをダウンロードする
- Admin接続用swfクライアントUnionAdmin.swfをダウンロードする
- ダウンロードしたUnion Serverのアーカイブを解凍する
- 解凍したフォルダにある、startserver.bat(startserver.sh)を実行する
- UnionAdmin.swfを実行する
- 接続先は、localhostとし、パスワードはpasswordで管理ツールが起動する
- UnionAdmin.swfからUnion Serverを停止することも出来る
Windows上での上記操作をキャプチャしてみました。あっという間にUnion Serverを操作出来きるようになることが分かると思います。
localhostのUnion Serverを試す
では、もう一度startserver.bat(startserver.sh)を実行して、Union Serverが起動しましょう。この状態で、Reactorから接続が可能な状態となります。
localhostへ繋ぐサンプル
起動時のログ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 2009-09-05 12:47:31,175 WARN - *** Starting Union Alpha 1.0.0 (build 283) *** 2009-09-05 12:47:31,175 WARN - ********************************************** 2009-09-05 12:47:31,175 WARN - UPC Version: 1.3.0 2009-09-05 12:47:31,470 WARN - Using CharSet [UTF-8] 2009-09-05 12:47:31,474 INFO - ContextManager initialized. 2009-09-05 12:47:31,545 WARN - UNION_HOME set to [/path/to/union/.] 2009-09-05 12:47:31,649 WARN - Gateway [IOGateway] bound to port [9100] on all local IP addresses. 2009-09-05 12:47:31,650 INFO - Gateway [IOGateway] added to the Server. 2009-09-05 12:47:31,869 WARN - Gateway [NIOGateway] bound to port [9101] on all local IP addresses. 2009-09-05 12:47:31,869 INFO - Gateway [NIOGateway] added to the Server. 2009-09-05 12:47:31,871 INFO - Loaded module type [class] with code [net.user1.union.servermodule.ServerStatsServerModule] 2009-09-05 12:47:31,872 WARN - Server module [serverStatsServerModule] loaded. 2009-09-05 12:47:31,882 WARN - POLICY_FILE attribute missing for Gateway [_ADMIN_GATEWAY_]. Using default [policy.xml]. 2009-09-05 12:47:31,882 WARN - Gateway [_ADMIN_GATEWAY_] bound to port [9110] on all local IP addresses. 2009-09-05 12:47:31,883 INFO - Gateway [_ADMIN_GATEWAY_] added to the Server. 2009-09-05 12:47:31,924 WARN - Banned list file [banned.txt] not found. Banned list not initiated. 2009-09-05 12:47:31,924 WARN - Admin Gateway Started. 2009-09-05 12:47:31,924 INFO - ContextManager started. 2009-09-05 12:47:31,924 WARN - Union Alpha 1.0.0 (build 283) Started....OK 2009-09-05 12:47:31,983 WARN - ----------------- SERVER STATS ------------------------------------------------------------------------- Memory Usage [init = 0(0K) used = 11201888(10939K) committed = 83230720(81280K) max = 85393408(83392K)] Thread Usage [9] ------------------------------------------------------------------------- |
connect時のログ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 2009-09-05 12:53:54,928 INFO - Gateway [IOGateway] accepted a connection. 2009-09-05 12:53:54,981 INFO - Gateway [IOGateway] accepted a connection. 2009-09-05 12:53:55,030 INFO - Client [1] connected to the server. UID [0:0:0:0:0:0:0:1%0] 2009-09-05 12:53:55,030 DEBUG - Server received from client [1] message [<U><M>u65</M><L><A>Reactor</A><A>Flash Player WIN 10,0,32,18 PlugIn (debug, remote); 1.0.0 (Build 247)</A><A>1.3.0</A></L></U>] 2009-09-05 12:53:55,049 DEBUG - Server sending to client [1] message [<U><M>u66</M><L><A>Union Alpha 1.0.0 (build 283)</A><A></A><A>1.3.0</A><A>true</A></L></U>] 2009-09-05 12:53:55,049 DEBUG - Server sending to client [1] message [<U><M>u29</M><L><A>1</A></L></U>] 2009-09-05 12:53:55,096 DEBUG - Server sending to client [1] message [<U><M>u8</M><L><A><![CDATA[]]></A><A>1</A><A><![CDATA[_CT]]></A><A><![CDATA[1252122835050]]></A><A>SUCCESS</A></L></U>] 2009-09-05 12:53:55,096 DEBUG - Server sending to client [1] message [<U><M>u8</M><L><A><![CDATA[]]></A><A>1</A><A><![CDATA[_IP]]></A><A><![CDATA[0:0:0:0:0:0:0:1%0]]></A><A>SUCCESS</A></L></U>] 2009-09-05 12:53:55,097 DEBUG - Server sending to client [1] message [<U><M>u63</M><L></L></U>] 2009-09-05 12:53:55,120 DEBUG - Server received from client [1] message [<U><M>u24</M><L><A><![CDATA[test]]></A><A><![CDATA[_DIE_ON_EMPTY|true|_MAX_CLIENTS|-1|_PASSWORD||_CLIENT_TIMEOUT|-1]]></A><A></A><A></A></L></U>] 2009-09-05 12:53:55,141 DEBUG - Room [test] initialized. 2009-09-05 12:53:55,142 DEBUG - Room [test] started. 2009-09-05 12:53:55,142 INFO - Room [test] initialized and started. 2009-09-05 12:53:55,142 DEBUG - Server sending to client [1] message [<U><M>u32</M><L><A><![CDATA[test]]></A><A>SUCCESS</A></L></U>] |
wonderflの投稿で試す
wonderflのunionタグのついた投稿を探して、forkしてみましょう。そして、Union Serverのホストをtryunion.comからlocalhostに変更します。すると、ローカルのUnion Serverへ接続するログが出力される事が確認出来ます。
もちろん、Union ServerのURLをlocalhostとした作品は自身のPCからしか正常に動作しないので注意して下さい。
設定の確認
Union Serverの設定はXMLファイルで行います。
policy.xml
Union ServerはFlash PlayerのSocket接続機能を利用します。Flash PlayerからSocket接続を行うためには、ソケット接続のポリシーファイルを用意する必要がありますので、Union Serverはソケット接続のポリシーファイルを自動で配布するようになっています。
policy.xmlではUnion Serverで利用するソケット接続のポリシーを設定します。
以下の例では、すべてのドメインに配置してあるswfからの接続を許可します。外部に公開するサーバでは必ず適切な設定に変更しましょう。特に管理用ポートからのアクセスは塞ぐと良いです。
1 2 3 | <cross-domain-policy> <allow-access-from domain="*" to-ports="9100,9101,9110" /> </cross-domain-policy> |
union.xml
Union Serverの動作を設定するファイルです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <union> <server> <admin> <port>9110</port> <password>password</password> </admin> <client_timeout>30</client_timeout> </server> <gateways> <gateway id="IOGateway" type="flash:io"> <port>9100</port> <policy_file>policy.xml</policy_file> </gateway> <gateway id="NIOGateway" type="flash:nio"> <port>9101</port> <policy_file>policy.xml</policy_file> </gateway> </gateways> <modules> <module> <id>serverStatsServerModule</id> <source type="class">net.user1.union.servermodule.ServerStatsServerModule</source> <attributes> <attribute name="interval">300</attribute> </attributes> </module> </modules> </union> |
最低限、管理用のパスワードは変更しておきましょう。その他モジュールの設定などを行うことができます。
管理用パスワード変更時の注意点
stopserver.bat(.sh)には、管理用のパスワードを記述する必要があります。
Windows環境の場合
stopserver.batを編集します。SET PASSWORDの値を変更します。管理用サーバのportを変更した際にはSET PORTの値を変更します。
SET HOST=localhost SET PORT=9110 SET PASSWORD=yourpassword java -cp lib\union.jar;lib\mariner.jar net.user1.union.core.UnionMain %HOST% %PORT% %PASSWORD% a5
Mac OS X, Linux環境の場合
stopserver.shを編集します。PASSWORDの値を変更します。管理用サーバのportを変更した際にはPORTの値を変更します。
#!/bin/sh HOST=localhost PORT=9110 PASSWORD=password java -cp lib/union.jar:lib/mariner.jar net.user1.union.core.UnionMain $HOST $PORT $PASSWORD a5
その他の設定
Configurationに詳しく記載されています。
ポートの確認
前述のとおり、Union Serverではソケット接続を行うので、ソケット接続のポリシーファイルを配布します。Flash Playerはソケット接続のポリシーファイルの取得時、ソケット接続先のサーバの843ポートに接続します。(このポートは変更することも可能)
また、union.xmlに指定したようにUnion Serverはデフォルトで9100ポートを使用します。
よって、Union Serverを外部に公開するような際には、ソケット接続のポリシーファイル配布用のポート(デフォルトで843)と、Union ServerのGatewayのポート(デフォルトで9100)のポートを開けておくのを忘れないようにしましょう。すでに843ポートで別のポリシーファイルを配布しているサーバでは、Union Serverのpolicy.xmlを設定してもその設定が反映されずに、動作しないということがあるので気をつけましょう。
Module
Moduleを使う事でUnion Serverの機能を拡張する事が出来ます。具体的には、サーバ側の各種イベント送出時のハンドラを登録することで、独自の挙動を追加出来ます。
また、Union Serverからの送信するMessage機能を使ってチャットボットのような機能を作成することも可能となります。
Server Module
Server Moduleはサーバ全体に影響を及ぼすモジュールです。
Room Module
Room Moduleは特定のRoomに影響を及ぼすモジュールです。
まとめ
さて、Union Serverをローカルにインストールする事でUnion Platformを使ったアプリケーション開発をローカルで行う事が出来るようになりました。
次回は、eclipseをインストールして、公式サイトのサンプルにあるようなモジュールを動かすまでの手順を紹介します。
関連記事
- UnionPlatform (1) 概要
- UnionPlatform (2) 概念
- Union Platform(3) 情報の共有化
- Union Platform(4) Reactorのイベント
- Union Platform(5) チャットを作る
- Union Platform(6) Union Server入門
- Union Platform(7) Union Server Module作成準備
- Union Platform(8) Moduleサンプル
hi naoto!
thanks for all your great tutorials and articles! i just wanted to let you know that we released Union 1.0 Alpha 4 today. please give it a try. i think you’ll like the new Union Admin features!
colin
hi colin!
Thank you for the comment.
Immediately, I try Union 1.0 Alpha4 and posted the following entry.
http://fla.la/archives/478
I’m looking forward to Union Updates!
[...] Union Platform(6) Union Server入門 [...]