1 7 package org.jboss.test.remoting.transport.socket.raw; 8 9 import java.io.BufferedInputStream ; 10 import java.io.BufferedOutputStream ; 11 import java.io.IOException ; 12 import java.io.ObjectInputStream ; 13 import java.io.ObjectOutputStream ; 14 import java.net.Socket ; 15 16 19 public class RawClient 20 { 21 protected String address = "localhost"; 22 protected int port = 6700; 23 24 public boolean enableTcpNoDelay = false; 25 public int timeout = 60000; 26 27 private Socket socket = null; 28 29 private ObjectOutputStream oos; 30 private ObjectInputStream objInputStream; 31 32 public void startClient() 33 { 34 while(true) 35 { 36 45 try 46 { 47 getSocket(); 48 49 oos.writeObject("This is the request"); 50 51 53 oos.reset(); 54 oos.writeObject(Boolean.TRUE); 58 oos.flush(); 59 oos.reset(); 60 61 62 Object obj = objInputStream.readObject(); 63 64 objInputStream.readObject(); 66 System.out.println("response: " + obj); 67 68 } 69 catch(IOException e) 70 { 71 e.printStackTrace(); 72 } 73 catch(ClassNotFoundException e) 74 { 75 e.printStackTrace(); 76 } 77 } 78 } 79 80 public void getSocket() throws IOException 81 { 82 if(socket == null) 83 { 84 try 85 { 86 socket = new Socket (address, port); 87 socket.setTcpNoDelay(enableTcpNoDelay); 88 90 BufferedOutputStream out = new BufferedOutputStream (socket.getOutputStream()); 91 BufferedInputStream in = new BufferedInputStream (socket.getInputStream()); 93 94 oos = new ObjectOutputStream (out); 95 objInputStream = new ObjectInputStream (in); 96 97 } 98 catch(IOException e) 99 { 100 e.printStackTrace(); 101 } 102 } 103 else 104 { 105 oos.reset(); 106 oos.writeByte(1); 107 oos.flush(); 108 oos.reset(); 109 objInputStream.readByte(); 110 } 112 } 113 114 public static void main(String [] args) 115 { 116 RawClient client = new RawClient(); 117 client.startClient(); 118 } 119 } | Popular Tags |