Mercurial > hg > FederatedLinda
view src/fdl/test/TestPSXLinda.java @ 93:a1d796c0e975 fuchita
Wait Read Tester
author | one |
---|---|
date | Tue, 25 May 2010 22:57:54 +0900 |
parents | 82a292aa41ad |
children | 0ea086f0e96f |
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(); System.out.println("Waiting...."+(cnt++)); } print_id(r); data.clear(); psx.out(PSX.META_STOP, data); psx.sync(); } 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()); } }