Broadcast of Java Datagram Programming

Source: Internet
Author: User


UDP broadcast is actually very simple. When I understand the IP address resolution scheme, I understand what broadcast is. Many articles call it multicast. I think it is better to call it broadcast, because multicasting refers to broadcasting and multicast, the processing in Java programs is naturally different. This article and the next article only emphasize the concept.
As mentioned above, the broadcast address includes the targeted broadcast address and the limited broadcast address. The TCP/IP protocol stipulates that the two addresses can only appear in the local network, and the router implements this rule, instead of forwarding packets whose target address is a broadcast address to other networks, multicast is different. The next article introduces multicast programming.
This broadcast program can simply become a broadcast program by modifying the target address of the message in the unicast program into a broadcast address.
Package recmail. multiservice;
Import java.net. DatagramSocket;
Import java.net .*;
Import java. io .*;
Import java. util. ArrayList;
Import java. util. Iterator;
Public class extends ramrecvsender_ B extends DataSwapListenerAdapter
Implements Runnable {
Public static final int DatagramPort = 10698;
Private java.net. DatagramSocket road;
Private InetAddress ia;
DatagramPacket dp;
Public static final int Datagram_Length = 8192;
Private DataPacket cdp;
Private boolean ishandling = true;
DataSwapEvent dsevent;
/**
* This constructor is used to receive data packets.
*/
Public DatagramRecvSender_ B (){
Try {
System. out. println ("recv ...");
Dsevent = new DataSwapEvent (this );
SocketAddress sa = new InetSocketAddress (
DatagramRecvSender_ B .DatagramPort );
// Specify at least the datagram receiving port, which is the only requirement on the receiving end. Of course, if the host is a multi-access host, road = new DatagramSocket (sa) is required );
Road = new DatagramSocket (datagramrecvsender_ B .20.ramport );

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.