Mercurial > hg > Applications > TreeVNC
diff src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java @ 1:75b54fd9e73a
add new package treevnc
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 03 Jul 2012 13:34:43 +0900 |
parents | |
children | dca3bd61b830 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java Tue Jul 03 13:34:43 2012 +0900 @@ -0,0 +1,57 @@ +package ac.ryukyu.treevnc.client; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; + +public class GetHostClient { + final int BUFSIZE = 1024; + final String MCASTADDR = "224.0.0.1"; + final int PORT = 8183; + private byte[] buf = new byte[BUFSIZE]; + private InetAddress mAddr; + private MulticastSocket soc; + private String str; + + public GetHostClient(String _str) { + str = _str; + } + + void createSocket() { + try { + mAddr = InetAddress.getByName(MCASTADDR); + soc = new MulticastSocket(); + soc.setTimeToLive(1); + } catch (IOException e) { + e.printStackTrace(); + } + } + + void sendData() { + buf = str.getBytes(); + // System.out.println("strlen"+str.length()); + // System.out.println("str"+str); + DatagramPacket sendPacket = new DatagramPacket(buf, str.length(), + mAddr, PORT); + try { + soc.send(sendPacket); + } catch (IOException e) { + e.printStackTrace(); + } + } +/* + @Override + public void run() { + createSocket(); + while (true) { + sendData(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + System.out.println(e); + } + } + } + */ +}