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。阅读简短的解释。如果您进行了任何修改,我想鼓励通过拉取请求为这个原始存储库做出贡献。