import java.io.*;
import java.io.File;
import java.net.*;
import java.net.UnknownHostException;
import java.net.InetAddress;



public class Rfc{
 protected String ip;
 protected int host;
 public BufferedReader reader;
 protected PrintWriter writer;
 

 
 public static void main(String[] args){
   try{InetAddress address = InetAddress.getLocalHost();

String ip = address.getHostAddress();
 System.out.println(ip);
   }catch(Exception e){
   
   System.out.println("error2"+e);
 
 
 }
  
  Rfc rfc =new Rfc(ip,80);
  rfc.setUpConnection();
  String s = rfc.getFile("/place.txt");
  rfc.connectiondown();
  System.out.println(s);
  
 }
 
 public void setUpConnection(){
   try{
   
     Socket client = new Socket(ip,host);
     
 
     reader = new BufferedReader(new InputStreamReader(client.getInputStream()));
  
     writer=new PrintWriter(client.getOutputStream());

   }catch(IOException e){
   System.out.println("error1"+e);
   }
   }
 
  
 public  Rfc(String ipx,int hostx){
 ip=ipx;
 host=hostx;
 }
 
 public String getFile(String a){
 StringBuffer all = new StringBuffer();
 try{ 
   File f = new File("/place.txt");
  System.out.println(f.exists());
  System.out.println(f.canRead());
   writer.println("/place.txt");
  
   writer.flush();

 String a1=null ;
 try {
   System.out.println(reader.read());
     System.out.println(1);
   
while((a1 =reader.readLine()) != null)
    all.append(a1+"\n");
 
}catch(Exception e){
   System.out.println("error2"+e);
 
 
 }
 }catch(Exception e){
   System.out.println("error2"+e);
 
 
 }
    
 //return all.toString();
 return reader.toString();
 }
 
 public void connectiondown(){
 try{
   reader.close();
 writer.close();
 }catch(Exception e){
   System.out.println("error3"+e);
 
 
 }
 }
 
 
 }

Edited 6 Years Ago by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

when ever i call reader(bufferedreader) it goes into a infinite loop or something like that

In your main method when you call

Rfc rfc =new Rfc(ip,80);

You mean the ip you have declared inside the method but it is not reachable since it is inside the try code block - move all of the code inside the try block.

This article has been dead for over six months. Start a new discussion instead.