1 import java.io.*; 2 import java.net.*; 3 4 import org.objectweb.joram.shared.stream.*; 5 import org.objectweb.joram.shared.client.*; 6 7 public class Proxy { 8 public static void main(String args[]) throws Exception { 9 int counter = 1; 10 ServerSocket server = new ServerSocket(16010); 11 12 while (true) { 13 try { 14 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 15 16 System.out.println("wait"); 17 Socket socket = server.accept(); 18 InputStream is = socket.getInputStream(); 19 OutputStream os = socket.getOutputStream(); 20 System.out.println("connected"); 21 int length = StreamUtil.readIntFrom(is); 22 System.out.println("reads: " + length); 23 String user = StreamUtil.readStringFrom(is); 24 String pass = StreamUtil.readStringFrom(is); 25 int key = StreamUtil.readIntFrom(is); 26 int timeout = StreamUtil.readIntFrom(is); 27 28 System.out.println(user + ", " + pass + ", " + key + ", " + timeout); 29 30 StreamUtil.writeTo(8, os); 31 StreamUtil.writeTo(0, os); 32 StreamUtil.writeTo(counter++, os); 33 34 int s = StreamUtil.readIntFrom(is); 35 CnxConnectRequest req = (CnxConnectRequest) AbstractJmsMessage.read(is); 40 System.out.println("receive: " + req); 41 42 CnxConnectReply reply = new CnxConnectReply(req, 12, "#0.0.12"); 43 reply.write(baos); 44 System.out.println("sends: " + baos.size()); 45 StreamUtil.writeTo(baos.size(), os); 46 baos.writeTo(os); 47 Thread.sleep(30000L); 48 socket.close(); 49 } catch (IOException exc) { 50 exc.printStackTrace(); 51 } 52 } 53 } 54 } 55 | Popular Tags |