Protokol jaringan virtual berorientasi pesan yang cepat, andal & tidak mengganggu untuk Java 6+.
Saat ini dalam versi alfa.
JNetRobust adalah protokol jaringan virtual yang berada di antara lapisan transport dan lapisan aplikasi.
Manfaat
Peringatan
Jika Anda tidak membutuhkan keandalan, gunakan UDP.
Jika Anda memerlukan keandalan dan Anda dapat menunggu hingga divalidasi, gunakan TCP.
Jika Anda memerlukan keandalan, namun mendapat manfaat dari menerima data yang tidak divalidasi tanpa latensi, cobalah JNetRobust.
Ini adalah perpustakaan dan tidak memberlakukan batasan pada cara Anda menggunakannya:
Anda dapat menggunakan implementasi referensi yang merekatkan semua bagian tersebut untuk memulai; contohnya tercantum di bawah ini.
Lihat halaman Wiki untuk informasi tambahan!
Berikut adalah contoh minimal dan lengkap penggunaan implementasi referensi yang disediakan:
Kode
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 );
}
}
}
Keluaran Konsol
[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.
Maven
<!-- 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 >
Pengaturan manual
Anda dapat mengunduh jar
dari bagian rilis dan mengimpornya ke jalur kelas Anda.
Anda dapat membaca dokumen di halaman IO JNetRobusts.
Masalah terbuka dan/atau permintaan tarik terbuka . Saran, laporan bug, perbaikan kode, dan fitur tambahan sangat diharapkan!
Hak Cipta (c) 2014 mucaho.
MPL 2.0. Baca penjelasan singkatnya. Saya ingin mendorong kontribusi ke repositori asli ini melalui permintaan tarik, jika Anda melakukan modifikasi apa pun.