Android send UDP broadcast, search server establish socket link

Source: Internet
Author: User

Application Scenario: The client (mobile phone, PC) needs to search for servers in the local area network and obtain the server address.


Method Introduction: The client sends the UDP broadcast, the service receives the client IP address after receiving the broadcast, then sends a socket link to the client, the client receives the socket link, obtains the server address.


Related knowledge:

UPD, TCP. TCP is a link-oriented, reliable means of communication. UDP is a non-link-oriented method of communication. The establishment of TCP is more troublesome than the "three-time handshake". The establishment of UDP is relatively simple, the sender just send the content, regardless of whether the receiver received. The transmission of UDP is divided into: unicast, multicast, broadcast. Where multicast and broadcast are implemented through a specific IP address within the TCP/IP protocol, for example, the address of a restricted broadcast is: 255.255.255.255.

A total of 65,535 network ports, the communication between the host needs to develop a port. Network ports are divided into three categories, recognized ports, registered ports, and dynamic and/or private ports.


Experimental method:

Four applications, of which two Android programs, two PC programs. Let the PC and Android take turns, or together as both client and server. The test results are: The UDP listener on the PC and the UDP initiator can run concurrently. But on Android phones, once the UDP service is listening on the port, the native can no longer send UDP broadcasts for that port.


Code Download: http://download.csdn.net/detail/qiushibaiyi/7531837


Network Port Data entry: Http://baike.baidu.com/view/43200.htm?fr=aladdin Click to open the link

Multicast and broadcast data entry: http://www.cnblogs.com/hnrainll/archive/2011/09/01/2162110.html Click to open link

Section Code Reference: http://download.csdn.net/download/xiaoxiaobian3310903/4502201# Click to open the link

Reference article: http://blog.sina.com.cn/s/blog_6c0a8fbb0100s3k5.html Click to open link


Code address: http://download.csdn.net/detail/qiushibaiyi/7531837 Click to open the link

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.