/*
Exercise : Ex 2(a)
Title : TCP Receiver Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class TCPreceiver
{
public static void main(String args[])
{
ServerSocket ss;
Socket s;
try
{
System.out.println("Waiting for Client........");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("Connection Done...!!");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
System.out.println("From : " + s.getInetAddress() );
fname=get.readLine();
fname="TR_" +fname;
System.out.println("file name is:" +fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)
fw.write(Integer.parseInt(c));
System.out.println("Contents Received..");
fw.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 2(a)
Title : TCP Sender Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class TCPsender
{
public static void main(String args[])
{
try
{
System.out.println("Enter the File Name you wanna transfer ...");
DataInputStream dis=new DataInputStream(System.in);
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!=-1)
put.println(c);
System.out.println("File Transfered....");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}
Exercise : Ex 2(a)
Title : TCP Receiver Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class TCPreceiver
{
public static void main(String args[])
{
ServerSocket ss;
Socket s;
try
{
System.out.println("Waiting for Client........");
ss=new ServerSocket(8081);
s=ss.accept();
System.out.println("Connection Done...!!");
BufferedReader get=new BufferedReader(new InputStreamReader(s.getInputStream()));
String fname;
System.out.println("From : " + s.getInetAddress() );
fname=get.readLine();
fname="TR_" +fname;
System.out.println("file name is:" +fname);
File f=new File(fname);
FileWriter fw=new FileWriter(f);
String c;
while((c=get.readLine())!=null)
fw.write(Integer.parseInt(c));
System.out.println("Contents Received..");
fw.close();
s.close();
}
catch(Exception e)
{}
}
}
/*
Exercise : Ex 2(a)
Title : TCP Sender Program..
Author :Aslam Jainul
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class TCPsender
{
public static void main(String args[])
{
try
{
System.out.println("Enter the File Name you wanna transfer ...");
DataInputStream dis=new DataInputStream(System.in);
String f=dis.readLine();
File f1=new File(f);
FileReader fr=new FileReader(f1);
Socket s=new Socket("192.168.208.118",8081);
PrintWriter put=new PrintWriter(s.getOutputStream(),true);
put.println(f);
int c=0;
while((c=fr.read())!=-1)
put.println(c);
System.out.println("File Transfered....");
fr.close();
s.close();
}
catch(Exception e)
{}
}
}