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 );