First question: UDP transmission screen broadcast (less than 64k). import javax.swing.jframe;import javax.swing.jlabel;import javax.swing.imageicon;import java.net.datagrampacket;import java.net.datagramsocket;class clientdemo{ Public static void main (String[] args) throws Exception{ clientui ui = new clientui (); new clientreceive (UI). Start (); }}class clientui extends JFrame{ private JLabel label; private Imageicon icon; public clientui () { ini (); } public void ini () { this.setbounds (0,0,600,400); This.setlayout(null); label = new jlabel (); label.setbounds (0,0,600,400); Label.setlayout (null); icon = new imageicon ("e:/ A.png "); label.seticon (icon); this.add (label); this.setvisible (True); } public void refreshimage (Byte[] image_arr) { label.seticon (New imageicon (Image_arr)); }}class clientreceive extends thread{ private datagramsocket socket; private ClientUI ui; public Clientreceive (Clientui ui) &NBsp;throws exception{ this.ui = ui; socket = new datagramsocket (8889); } public void run () { try{ int i = 0; while (True) { byte[] buf = new byte[1024*60]; datagrampacket packet = new datagrampacket (buf,buf.length); socket.receive (packet); &nBsp; int length = packet.getlength (); ui.refreshimage (BUF); thread.sleep (1000); } }catch (exception e) { E.printstacktrace (); } }}import java.net.datagramsocket;import java.net.datagrampacket;import java.net.inetaddress;import java.awt.rectangle;import java.awt.image.bufferedimage;import java.awt.robot;import Javax.imageio.imageio;import java.io.fileoutputstream;import java.io.bytearrayoutputstream;import java.util.zip.gzipoutputstream;class&nbSp Serverdemo{ public static void main (String[] args) throws exception{ datagramsocket socket = new datagramsocket (8888); int i = 0; while (True) { byte[] buf = null; buf = new byte[1024*60]; rectangle rect = new rectangle (0,0,600,400); BufferedImage image = (New robot ()). Createscreencapture (Rect); bytearrayoutputstream baos = new bytearrayoutputstream (); imageio.write (image, "jpg", BAOs); byte[] zipdata = baos.tobytearray () ; datagrampacket packet = new datagrampacket (ZipData, Zipdata.length); inetaddress addr = inetaddress.getbyname ("127.0.0.1"); packet.setaddress (addr); Packet.setport (8889); socket.send ( packet); i++; thread.sleep (; ) system.out.println (i); } }}
This article is from the "Forest Sensitive" blog, please be sure to keep this source http://senlinmin.blog.51cto.com/6400386/1790128
Big Data Java Foundation 18th day job