Author: jfrederic.clere(a)jboss.com
Date: 2008-10-20 07:53:50 -0400 (Mon, 20 Oct 2008)
New Revision: 1964
Added:
sandbox/mod_jk/PongServ.java
Log:
Server to test cping/cpong interaction.
Added: sandbox/mod_jk/PongServ.java
===================================================================
--- sandbox/mod_jk/PongServ.java (rev 0)
+++ sandbox/mod_jk/PongServ.java 2008-10-20 11:53:50 UTC (rev 1964)
@@ -0,0 +1,54 @@
+import java.io.*;
+import java.net.*;
+
+class PongServ {
+ public static void main(String[] argv)
+ {
+ int wait = 3000;
+ if (argv.length == 1)
+ wait = Integer.parseInt(argv[0]);
+ System.out.println("PongServ wait: " + wait);
+ ServerSocket serverSocket = null;
+ try {
+ serverSocket = new ServerSocket(8009);
+ } catch (IOException e) {
+ System.out.println("Could not listen on port: 8009");
+ System.exit(-1);
+ }
+ Socket clientSocket = null;
+ try {
+ clientSocket = serverSocket.accept();
+ } catch (IOException e) {
+ System.out.println("Accept failed: 8009");
+ System.exit(-1);
+ }
+ byte[] buf = new byte[1024];
+ int num;
+ byte cpong[] = { 'A' , 'B', '\0' , (byte)0x02 , (byte)0x09 };
+ InputStream clientInput = null;
+ OutputStream clientOutput = null;
+ try {
+ clientSocket.setSoTimeout(wait);
+ clientInput = clientSocket.getInputStream();
+ clientOutput = clientSocket.getOutputStream();
+ while ((num = clientInput.read(buf)) != -1) {
+ System.out.println(".");
+ }
+ System.out.println("num " + num);
+ } catch (InterruptedIOException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ System.out.println("Could not read from port: 8009");
+ System.exit(-1);
+ }
+
+ /* write cpong */
+ try {
+ clientOutput.write(cpong);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+}
Show replies by date