Mercurial > hg > FederatedLinda
view src/fdl/test/transfer/two/ProtocolEngine.java @ 66:82a292aa41ad
fix
author | one |
---|---|
date | Sat, 06 Jun 2009 14:23:02 +0900 |
parents | b342dc9b52eb |
children | 0ea086f0e96f |
line wrap: on
line source
package fdl.test.transfer.two; import java.io.IOException; import java.nio.ByteBuffer; import fdl.FederatedLinda; import fdl.PSXLinda; import fdl.PSXReply; public class ProtocolEngine extends Thread{ private static PSXLinda psx; private static String name; static FederatedLinda fdl1; static String host = "127.0.0.1"; static int port1 = 10001; static int port2 = 10002; private static int id = 10; private static PSXLinda psx1; private static boolean running; private static ByteBuffer data2 = ByteBuffer.allocate(10); public static void main(String[] args){ fdl1 = FederatedLinda.init(); try { System.out.println(name); psx = fdl1.open(host,port1); System.out.println("Connect Host1"); psx1 = fdl1.open(host,port2); System.out.println("Connect Host2"); // Host1にデータを送信する。 testSend(psx); // psxにデータを用意 transfer(psx,psx1); } catch (IOException e) { e.printStackTrace(); } } private static void testSend(PSXLinda psx2) throws IOException { ByteBuffer send = ByteBuffer.allocate(10); send.putInt(12); send.flip(); psx2.out(id, send); psx2.sync(); } private static void transfer(PSXLinda psx2, PSXLinda psx12) throws IOException { PSXReply in = psx2.in(id); while (running) { if(in.ready()){ //psx1にデータを書き出し data2 = in.getData(); psx12.out(id,data2); //runningフラグをfalseする running = false; fdl1.sync(0); break; } fdl1.sync(); } } }