Coder Social home page Coder Social logo

lan_search_communication's Introduction

Android下实现局域网设备发现与通信

在使用Android开发智能设备时,一般会分为用于遥控与管理的Host端,和用于执行个性功能的Slave端,二者可以借助网络或蓝牙等途径实现通信。

局域网设备发现

如果是借助网络通信,那就必须知道对方的ip地址,而常见的网络环境中ip地址一般是通过DHCP服务动态分配的,所以事先无法确定对方的ip地址。为了确定对方的地址,可以通过向局域网内发送查找设备的广播,收到广播的Slave端就知道了Host端的ip地址,在向Host端发送应答包之后,双方就都知道了对方的ip地址。

局域网设备通信

在Host端与Slave端互相知道ip地址后,就可以实现局域网通信了。局域网通信一般通过TCP或UDP实现,TCP的优势在于它的可靠性,通过TCP传送的数据不丢失、无差错、不重复且按序到达,但只支持一对一,效率比UDP低;UDP的优势在于效率比TCP高,支持一对一、一对多、多对一、多对多,但不保证可靠性,网络差的环境下可能丢包和顺序错乱。因此如果对可靠性要求较高,建议使用TCP,如果对实时性要求较高则可以使用UDP。

lan_search_communication's People

Contributors

wei-gong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.