Hiya,

I've been messing about with firewall tunneling recently, but am having
massive problems with URLConnection. It seems that there is one combination
of sequence of events and streams used which actually makes it work.. take
the Post method for example.. the online docs say the client should do the
following:

   private final String serverURLin  = new String("http://localhost:9876/");
   private URLConnection urlConClientIn;
   private PrintStream clientOutStream;
         
   <snip>
   
   urlConClientOut = (new URL(serverURLin)).openConnection();
   urlConClientOut.setDoOutput(true);
   urlConClientOut.setUseCaches(false);
   clientOutStream = new PrintStream( urlConClientOut.getOutputStream() );
   clientOutStream.println("Linux");
   clientOutStream.println("Is");
   clientOutStream.println("Lovely");
   clientOutStream.close();       

Yet this doesnt seem to send anything to the server. Now I know the server
is running ok because by entering http://localhost:9876/ in netscape, it
connects and the server gets all the header information from the url
request.. so what's wrong with that client?

Here is the server code I have:

   private Socket socketIn;
   private DataInputStream sInStream;
   
   <snip stuff to assign socketIn a Socket from ServerSocket.accept()>
   
   sInStream = new DataInputStream
   (new BufferedInputStream(socketIn.getInputStream()));
   
   int contentLength = 0;
   String inStr;
   
   // Read the headers
   do
   {
     inStr = sInStream.readLine();
     System.out.println(inStr);
     // if inStr has Content-length, read the 
     // length into a variable here
     if (inStr.startsWith("Content-length:"))
     {
       String s =
       inStr.substring(16, inStr.length());
       System.out.println("Got clength "+s);
       contentLength = Integer.parseInt(s.trim());
     }
   } while (!inStr.equals (""));
   
   But it always gets 'stuck' at the sInStream.readLine() !
   
   If anyone has any pointers, or working code which does roughly the same
as this, please help!


Ta,


John Baker

-- 
John Baker, Software Engineer, Java coder, Salad sarnie lover.
 Work: (01203) 562000 ext 4153
 Home: (01203) 601890

Reply via email to