Mercurial > hg > Database > Alice
view src/main/java/alice/daemon/MulticastConnection.java @ 419:aefbe41fcf12 dispose
change tab to space
author | sugi |
---|---|
date | Tue, 15 Jul 2014 16:00:22 +0900 |
parents | 60eee1fb0fd3 |
children | 2f2623484b77 |
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.codesegment.SingletonMessage; import alice.datasegment.Command; public class MulticastConnection extends Connection { private DatagramChannel dc; private SocketAddress sAddr; public MulticastConnection(DatagramChannel d, SocketAddress s) { dc = d; sAddr = s; } // may need to add infomation who send on ds. @Override public synchronized void write(Command cmd){ CommandMessage cmdMsg = cmd.convert(); ByteBuffer buffer; try { buffer = ByteBuffer.wrap(SingletonMessage.getInstance().write(cmdMsg)); 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(); } } }