Mercurial > hg > Database > Alice
view src/main/java/alice/daemon/MulticastConnection.java @ 547:e91a574b69de dispose
remove index
author | Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 18 Aug 2015 16:15:17 +0900 |
parents | f3f7e256ee03 |
children |
line wrap: on
line source
package alice.daemon; import java.io.IOException; import java.net.SocketAddress; import java.nio.ByteBuffer; import java.nio.channels.DatagramChannel; import alice.datasegment.Command; public class MulticastConnection extends Connection { private DatagramChannel dc; private SocketAddress sAddr; public MulticastConnection(DatagramChannel d, SocketAddress s, AliceDaemon alice) { dc = d; sAddr = s; this.alice = alice; } // may need to add infomation who send on ds. @Override public synchronized void write(Command cmd){ ByteBuffer buffer = cmd.convert(alice); try { while (buffer.hasRemaining()){ dc.send(buffer, sAddr); } } catch (IOException e) { e.printStackTrace(); } } @Override public void close(){ try { dc.close(); } catch (IOException e) { e.printStackTrace(); } } public void receive(ByteBuffer receiveData){ try { dc.receive(receiveData); } catch (IOException e) { e.printStackTrace(); } } }