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);
}
}
}
appooti 0 Newbie Poster
appooti 0 Newbie Poster
stephen84s 550 Nearly a Posting Virtuoso Featured Poster
apines 116 Practically a Master Poster Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.