Mercurial > hg > FederatedLinda
view src/fdl/test/TestPSXLinda.java @ 122:ad73eacf560a default tip
remove warning
author | e095732 |
---|---|
date | Thu, 07 Feb 2013 22:32:26 +0900 |
parents | 0ea086f0e96f |
children |
line wrap: on
line source
/* * @(#)TestPSXLinda.java 1.1 06/04/01 * * Copyright 2006 Shinji KONO * Test PSX Lidna */ package fdl.test; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import fdl.FederatedLinda; import fdl.PSX; import fdl.PSXLinda; import fdl.PSXReply; /** * PSXLinda stream * * @author Shinji Kono * * @param localhost The host to connect to * @param Port The port to connect to at the host */ class TestPSXLinda { static int id; public static void main (String args[]) { FederatedLinda fdl; PSXLinda psx; String host; int port = 10000; PSXReply r; InetSocketAddress localAddress; try { localAddress = new InetSocketAddress(InetAddress.getLocalHost(), port); host = localAddress.getHostName(); } catch (UnknownHostException e) { host = "localhost"; } try { fdl = FederatedLinda.init(); psx = fdl.open(host,port); r = psx.in(65535); fdl.sync(1); System.out.println("Connected."); ByteBuffer data = ByteBuffer.allocate(10); data.putInt(10); data.flip(); psx.out(1,data); int cnt=0; while(!r.ready()) { // psx.sync(1000); psx.sync(0); System.out.println("Waiting...."+(cnt++)); } print_id(r); data.clear(); psx.out(PSX.META_STOP, data); psx.sync(0); } catch (IOException e) { System.err.println("Communication failure."); } } public static void print_id (PSXReply ans) throws IOException { ByteBuffer r = ans.getData(); System.out.print("ID = "); System.out.write(r.array()); } }