資源描述:
《組播實(shí)現(xiàn)udp遠(yuǎn)程桌面》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、組播實(shí)現(xiàn)UDP遠(yuǎn)程桌面組播實(shí)現(xiàn)UDP遠(yuǎn)程桌面?服務(wù)端:packagemultiCast;importjava.awt.Dimension;importjava.awt.Graphics2D;importjava.awt.Rectangle;importjava.awt.RenderingHints;importjava.awt.Robot;importjava.awt.Toolkit;importjava.awt.image.BufferedImage;importjava.io.ByteArrayOutputStream;importjava.net.DatagramPacket;impor
2、tjava.net.InetAddress;importjava.net.MulticastSocket;importjavax.imageio.ImageIO;publicclassMultiCastServerextendsThread{???privatestaticintportTem=9999;//?端口號(hào)???privatestaticStringmutiAddr="230.0.0.1";//?組播IP地址???privateInetAddressinetAddress;//?組播消息的目標(biāo)地址,及發(fā)送人的地址???privateMulticastSocketmulticastSo
3、cket;//?組播發(fā)送端套接字???privateRobotrobot;//robot用于獲得本地圖片???publicMultiCastServer(){???????try{??????????inetAddress=InetAddress.getByName(mutiAddr);//?從組播地址中獲得具體的發(fā)送者的地址??????????multicastSocket=newMulticastSocket();???????}catch(Exceptione){??????????e.printStackTrace();??????????//TODO:handleexception?
4、??????}???}???publicvoidrun(){???????Dimensionsize=Toolkit.getDefaultToolkit().getScreenSize();//?獲得屏幕大小???????Rectanglerec=newRectangle(0,0,(int)size.getWidth(),(int)size??????????????.getHeight());//?畫一個(gè)窗體???????try{??????????while(true){??????????????//?抓取一張屏幕圖片??????????????robot=newRobot();????
5、??????????BufferedImageimage=robot.createScreenCapture(rec);//?把屏幕圖片放入BufferedImage中??????????????BufferedImagelittleimage=resize(image,600,500);??????????????ByteArrayOutputStreambout=newByteArrayOutputStream();//?定義一個(gè)比特?cái)?shù)組輸出流,用來發(fā)送上面獲得的圖片????????ImageIO.write(littleimage,"jpeg",bout);//?調(diào)用ImageIO把??
6、????????????????????????????????????????//?圖片以JPEG的形式寫入到bout輸出流中???????????????????????byte[]b=bout.toByteArray();//?獲得bout里的數(shù)據(jù)字節(jié),放入b中?????????????????????????????/*out.writeInt(b.length);//?用DataOutputStreamout發(fā)送圖片大小??????????????out.write(b);//?把圖片字節(jié)寫入out中??????????????out.flush();//?刷新?????*/????
7、?????????????????????DatagramPacketdp=newDatagramPacket(b,b.length,inetAddress,portTem);//設(shè)置發(fā)送包的長(zhǎng)度和端口??????????????multicastSocket.send(dp);????????????????????????????????????????????Thread.sleep(100