diff 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
line wrap: on
line diff
--- a/src/treeVnc/MyRfbProtoProxy.java	Tue Feb 21 04:10:12 2012 +0900
+++ b/src/treeVnc/MyRfbProtoProxy.java	Thu Feb 23 16:18:42 2012 +0900
@@ -13,6 +13,9 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.BindException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.nio.ByteBuffer;
@@ -757,7 +760,7 @@
 
 				startTiming();
 				readFully(inputData.array(), 0, inputData.capacity());
-				System.out.println(dataLen);
+				//System.out.println(dataLen);
 				inputData.limit(dataLen - 20);
 				stopTiming();
 
@@ -947,13 +950,37 @@
 					/* if socket closed cliList.remove(newCli); */
 				}
 			}
+			
+			void broadCastCommunication(byte[] buf,int len) {
+				String mcastAddr = "224.0.0.1";
+				int port = 8192;
+						
+				try {
+					InetAddress mAddr = InetAddress.getByName(mcastAddr);
+					MulticastSocket soc = new MulticastSocket();
+					DatagramPacket sendPacket =null;
+					soc.setTimeToLive(100);
+					
+//					System.out.println("Multicast = " + mcastAddr);
+					//while(buf != null) {
+//						int len = System.in.read(buf);
+					sendPacket = new DatagramPacket(buf,len,mAddr,port);
+					soc.send(sendPacket);
+//					}
+					soc.close();
+				} catch(IOException e) {
+					e.printStackTrace();
+				}
+				
+			}
 
 			public void writeToClient(final OutputStream os,
 					LinkedList<ByteBuffer> bufs, int inputIndex)
 					throws IOException {
 				while (inputIndex < bufs.size()) {
 					ByteBuffer b = bufs.get(inputIndex++);
-					os.write(b.array(), b.position(), b.limit());
+					broadCastCommunication(b.array(),b.limit()-b.position());
+//					os.write(b.array(), b.position(), b.limit());
 				}
 				os.flush();
 			}