Java Datagram programming unicast

Source: Internet
Author: User


In fact, unicast is a message sent from the source host to another target host, with only one recipient.
First, write the transceiver class mongoramrecvsender_s. This class sends both the datagram and the datagram, sends all the images in a folder, one by one, and receives the data in one thread, each time a file is collected, an event is activated and the event processor processes the event.
Class list:
Package recmail. multiservice;
Import java.net. DatagramPacket;
Import java.net. DatagramSocket;
Import java.net. SocketException;
Import java.net. SocketAddress;
Import java.net. UnknownHostException;
Import java.net. InetSocketAddress;
Import java. io. IOException;
Import java. util. ArrayList;
Import java.net. InetAddress;
Import java. io. File;
Import java. util. Iterator;
Public class extends ramrecvsender_s 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_s (){
Try {
System. out. println ("recv ...");
Ia = InetAddress. getByName ("localhost"); // 192.168.0.17 "127.0.0.1"
Dsevent = new DataSwapEvent (this );
SocketAddress sa = new InetSocketAddress (ia,
DatagramRecvSender_s.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 );

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.