/**
*
* Copyright 2013 Paul Scherrer Institute. All rights reserved.
*
* This code is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This code is distributed in the hope that it will be useful, but without any
* warranty; without even the implied warranty of merchantability or fitness for
* a particular purpose. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see .
*
*/
package ch.psi.fdaq;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/**
* Simple socket client to connect to the fdaq black box.
* @author ebner
*
*/
public class SocketClient {
/**
* Requires connection to:
* ssh -L9999:mchip015:2233 x10da-gw
*
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
// Socket echoSocket = new Socket("localhost", 9999);
Socket echoSocket = new Socket("mchip015", 2233);
DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream());
DataInputStream in = new DataInputStream(echoSocket.getInputStream());
int nMessages = 100;
// struct fdaqbloc_in {int fnum;int nsample;};
ByteBuffer bytebuffer = ByteBuffer.allocate(2*4); // 2 times Integers
bytebuffer.order(ByteOrder.LITTLE_ENDIAN);
bytebuffer.putInt(26);
bytebuffer.putInt(nMessages);
out.write(bytebuffer.array());
out.flush();
for (int t=0;t>16)&0xffff;
int c = buffer.getInt();
int c1 = c&0xffff;
int c2 = (c>>16)&0xffff;
int d = buffer.getInt();
System.out.println(a+ " " +b1+ " " +b2+ " " + c1+ " " +c2+ " " +d );
}
out.close();
in.close();
echoSocket.close();
}
}