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 頁面上的文件。
未解決的問題和/或未解決的拉取請求。非常歡迎建議、錯誤回報、程式碼改進和附加功能!
版權所有 (c) 2014 mucaho。
MPL 2.0。閱讀簡短的解釋。如果您進行了任何修改,我想鼓勵透過拉取請求為這個原始儲存庫做出貢獻。