Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created January 8, 2010 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pklaus/272095 to your computer and use it in GitHub Desktop.
Save pklaus/272095 to your computer and use it in GitHub Desktop.
Small Java speed test for the ethersex platform.
// original script by Oliver Reimann
// <http://list.zerties.org/pipermail/ethersex-devel/attachments/20090223/36379536/client3.java>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
class client3 {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
String datasend(String outText){
out.println(outText); // Send data over socket
try{
return in.readLine(); // Receive text from server
} catch (IOException e){
System.out.println("Read failed");
System.exit(1);
}
return null;
}
public void listenSocket(String HostName, int Port){
// Create socket connection
try{
socket = new Socket( HostName , Port );
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (UnknownHostException e) {
System.out.println("Unknown host: " + HostName);
System.exit(1);
} catch (IOException e) {
System.out.println("No I/O");
System.exit(1);
}
}
//=====================================================================
public static void main(String[] args){
int port = 2701;
String ecmd = "adc get";
int intmax = 100;
String address = "";
if (args.length > 0) {
address = args[0];
} else {
System.err.println("No Address supplied, please give an IP address as first/single argument!");
System.exit(1);
}
client3 conn1 = new client3();
conn1.listenSocket(address, port);
long start = System.currentTimeMillis();
String line="";
for (int i=0;i<intmax;i++) {
line = conn1.datasend(ecmd);
}
System.out.println("ECMD sent: " + ecmd + ". Last response received: " + line);
long elapsed = System.currentTimeMillis() - start;
System.out.printf("time per cycle: %3.2f ms, which is equivalent to a rate of: %3.0f /s\n" ,
(double) elapsed/intmax,
(double) intmax/elapsed*1000.0 );
}
}
#!/bin/bash
javac client3.java
echo "OK, built client3. Now running client3."
java client3 $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment