Ingress network is an open-source library for android Network Communication Based on jmdns and netty, and ingress networkjmdns

Source: Internet
Author: User

Ingress network is an open-source library for android Network Communication Based on jmdns and netty, and ingress networkjmdns

Currently, many open-source network communication libraries for android are mostly based on http, such as Volley and android-async-http. network communication over the WAN is a good solution, for LAN communication scenarios, the above-mentioned http-based network communication is still effective, but not all servers use http Services. Dedicated Network is generated under this requirement, it implements automatic service discovery based on jmdns, zero network configuration, and network communication between android devices based on netty.

              

 

(1) The message model receivmessage transport network defines a message model called publish message, which contains three important members: pai_apptype appType: The application type of the message. After the producer network receives the message, this class can be used to determine the upper-layer message listening object to which the message will be sent (iw.msglistener ). String peerAddress: used by the server. The consumer network supports multiple clients to connect to a server at the same time. The server sends a message to one of the clients. You must specify the address of the client, Object content: the real content is required by the application layer of the message. The application layer can customize the content class according to the business, and only needs this class to implement Serializable. (2) The message communication entity consumer network defines an interface class INetworkConnection. Through this interface class, We Can Customize various specific communication entities, movie network defines two communication entity classes based on netty: NettyClient and NettyServer. These two classes implement the INetworkConnection interface.
public interface INetworkConnection { /**  * * @Title: start   * @Description: cli/svr endpoint connects into network(connect/bind) * void * @throws  */ public void start();  /**  * * @Title: send   * @Description: send msg to peer, notice: * for supporting cli:svr=*:1 * if svr sends msg to cli, mirrormessage req must set peerAddress. * if cli sends msg to svr, peerAddress not need set. * @param req * @return * MIRROR_TRANSFSTATUS * @throws  */ public MIRROR_NETSTATUS send(MirrorMessage req);  /**  * * @Title: stop   * @Description: just close network connection, you can start again for connecting again * recommend using stop for simple. * void * @throws  */ public void stop();  /**  * * @Title: close   * @Description: close network connection and release all resources. * void * @throws  */ public void close();  /**  * * @Title: setMirrorMsgListener   * @Description: set msglistener for recving msg from peers, * you are allowed registering listener once for each appType. * @param appType * @param li * @return * boolean * @throws  */ public boolean setMirrorMsgListener(MIRROR_APPTYPE appType, IMirrorMsgListener li);  /**  * * @Title: isClosed   * @Description: check if network connection was closed. * @return * boolean * @throws  */ public boolean isClosed();}

 

The communication entity (nettyclient, nettyserver) sets the listening object for each service layer (specified by ipv_apptype) through the setjavasmsglistener method to Implement Asynchronous Communication and receive peer messages.

 

Implementation Code and user guide for secure network, visit the https://github.com/europelee/MirrorNetwork

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.