Mercurial > hg > Members > you > BroadCastTreeVNC
comparison src/treeVnc/MyRfbProtoProxy.java @ 1:1d5cebe3bca0
update
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 23 Feb 2012 16:18:42 +0900 |
parents | 756bfaf731f3 |
children | 5d72f4c7371d |
comparison
equal
deleted
inserted
replaced
0:756bfaf731f3 | 1:1d5cebe3bca0 |
---|---|
11 import java.io.ByteArrayOutputStream; | 11 import java.io.ByteArrayOutputStream; |
12 import java.io.IOException; | 12 import java.io.IOException; |
13 import java.io.InputStream; | 13 import java.io.InputStream; |
14 import java.io.InputStreamReader; | 14 import java.io.InputStreamReader; |
15 import java.net.BindException; | 15 import java.net.BindException; |
16 import java.net.DatagramPacket; | |
17 import java.net.InetAddress; | |
18 import java.net.MulticastSocket; | |
16 import java.net.ServerSocket; | 19 import java.net.ServerSocket; |
17 import java.net.Socket; | 20 import java.net.Socket; |
18 import java.nio.ByteBuffer; | 21 import java.nio.ByteBuffer; |
19 import java.util.Iterator; | 22 import java.util.Iterator; |
20 import java.util.LinkedList; | 23 import java.util.LinkedList; |
755 len.limit(4); | 758 len.limit(4); |
756 ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); | 759 ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); |
757 | 760 |
758 startTiming(); | 761 startTiming(); |
759 readFully(inputData.array(), 0, inputData.capacity()); | 762 readFully(inputData.array(), 0, inputData.capacity()); |
760 System.out.println(dataLen); | 763 //System.out.println(dataLen); |
761 inputData.limit(dataLen - 20); | 764 inputData.limit(dataLen - 20); |
762 stopTiming(); | 765 stopTiming(); |
763 | 766 |
764 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); | 767 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); |
765 inputs.add(inputData); | 768 inputs.add(inputData); |
945 } catch (IOException e1) { | 948 } catch (IOException e1) { |
946 } | 949 } |
947 /* if socket closed cliList.remove(newCli); */ | 950 /* if socket closed cliList.remove(newCli); */ |
948 } | 951 } |
949 } | 952 } |
953 | |
954 void broadCastCommunication(byte[] buf,int len) { | |
955 String mcastAddr = "224.0.0.1"; | |
956 int port = 8192; | |
957 | |
958 try { | |
959 InetAddress mAddr = InetAddress.getByName(mcastAddr); | |
960 MulticastSocket soc = new MulticastSocket(); | |
961 DatagramPacket sendPacket =null; | |
962 soc.setTimeToLive(100); | |
963 | |
964 // System.out.println("Multicast = " + mcastAddr); | |
965 //while(buf != null) { | |
966 // int len = System.in.read(buf); | |
967 sendPacket = new DatagramPacket(buf,len,mAddr,port); | |
968 soc.send(sendPacket); | |
969 // } | |
970 soc.close(); | |
971 } catch(IOException e) { | |
972 e.printStackTrace(); | |
973 } | |
974 | |
975 } | |
950 | 976 |
951 public void writeToClient(final OutputStream os, | 977 public void writeToClient(final OutputStream os, |
952 LinkedList<ByteBuffer> bufs, int inputIndex) | 978 LinkedList<ByteBuffer> bufs, int inputIndex) |
953 throws IOException { | 979 throws IOException { |
954 while (inputIndex < bufs.size()) { | 980 while (inputIndex < bufs.size()) { |
955 ByteBuffer b = bufs.get(inputIndex++); | 981 ByteBuffer b = bufs.get(inputIndex++); |
956 os.write(b.array(), b.position(), b.limit()); | 982 broadCastCommunication(b.array(),b.limit()-b.position()); |
983 // os.write(b.array(), b.position(), b.limit()); | |
957 } | 984 } |
958 os.flush(); | 985 os.flush(); |
959 } | 986 } |
960 }; | 987 }; |
961 clients++; | 988 clients++; |