Big Data Java Foundation 18th day job

Source: Internet
Author: User

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

Related Article

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.