jnetrobust
1.0.0
Java 6 以降向けの高速で信頼性が高く、非侵入的なメッセージ指向の仮想ネットワーク プロトコル。
現在はアルファ版です。
JNetRobust は、トランスポート層とアプリケーション層の間に存在する仮想ネットワーク プロトコルです。
利点
注意事項
信頼性が必要ない場合は、UDP を使用してください。
信頼性が必要で、検証されるまで待つことができる場合は、TCP を使用してください。
信頼性は必要だが、遅延なしで未検証のデータを受信できる利点がある場合は、JNetRobust を試してください。
これはライブラリなので、使用方法に制限はありません。
これらすべての部分を結合するリファレンス実装を使用して開始できます。例を以下に示します。
追加情報については、Wiki ページを参照してください。
以下は、提供されたリファレンス実装を使用する最小限の完全な例です。
コード
public class BidirectionalMain {
public static void main ( String [] args ) throws Exception {
String receivedMessage ;
// host addresses
InetSocketAddress ADDRESS_A = new InetSocketAddress ( InetAddress . getLocalHost (), 12345 );
InetSocketAddress ADDRESS_B = new InetSocketAddress ( InetAddress . getLocalHost (), 12346 );
// setup ProtocolHosts using the host's local address and registering all serialization dataTypes
// ProtocolHost supports multiplexing between different peers using respective topicId, remote address and dataType
ProtocolHost protocolHostA = new ProtocolHost ( "A" , ADDRESS_A , String . class );
ProtocolHandle < String > protocolHandleA = protocolHostA . register ( Byte . MIN_VALUE , ADDRESS_B );
ProtocolHost protocolHostB = new ProtocolHost ( "B" , ADDRESS_B , String . class );
ProtocolHandle < String > protocolHandleB = protocolHostB . register ( Byte . MIN_VALUE , ADDRESS_A );
// send from A
protocolHandleA . send ( Arrays . asList ( "Hi!" , "How you doing?" ));
System . out . println ();
Thread . sleep ( 100 );
// receive at B
while (( receivedMessage = protocolHandleB . receive ()) != null ) {
System . out . println ( "<B> t " + receivedMessage );
}
// send from B
protocolHandleB . send ( "Howdy! Fine, thanks." );
System . out . println ();
Thread . sleep ( 100 );
// receive at A
while (( receivedMessage = protocolHandleA . receive ()) != null ) {
System . out . println ( "<A> t " + receivedMessage );
}
}
}
コンソール出力
[A]: Data sent -32767 Hi!
[A]: Data sent -32766 How you doing?
[B]: Data received ordered -32767 Hi!
[B]: Data received -32767 Hi!
[B]: Data received ordered -32766 How you doing?
[B]: Data received -32766 How you doing?
[B]: Newest data received -32766 How you doing?
<B> Hi!
<B> How you doing?
[B]: Data sent -32767 Howdy! Fine, thanks.
[A]: Data was received at other end -32767 Hi!
[A]: Data was received at other end -32766 How you doing?
[A]: Data received ordered -32767 Howdy! Fine, thanks.
[A]: Data received -32767 Howdy! Fine, thanks.
[A]: Newest data received -32767 Howdy! Fine, thanks.
<A> Howdy! Fine, thanks.
メイビン
<!-- JNetRobust library; mandatory -->
< dependency >
< groupId >com.github.mucaho</ groupId >
< artifactId >jnetrobust-core</ artifactId >
< version >0.0.2</ version >
</ dependency >
<!-- JNetRobust examples; optional -->
< dependency >
< groupId >com.github.mucaho</ groupId >
< artifactId >jnetrobust-samples</ artifactId >
< version >0.0.2</ version >
</ dependency >
手動セットアップ
リリース セクションからjar
をダウンロードし、クラスパスにインポートできます。
JNetRobusts の IO ページでドキュメントを読むことができます。
オープンな問題やオープンなプルリクエスト。提案、バグレポート、コードの改善、追加機能は大歓迎です。
Copyright (c) 2014 ムカホ.
MPL2.0。短い説明を読んでください。変更を加えた場合は、プル リクエストを通じてこの元のリポジトリに貢献することをお勧めします。