/* Client.java */
import java.io.*;
import java.net.*;
class client
{
public static void main(String args[]) throws Exception
{
String fname=null;
String readval=null;
Socket skt=new Socket("192.168.4.93",1900);//host and port number
InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
DataInputStream dis=new DataInputStream(is);
DataOutputStream dos=new DataOutputStream(os);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nENTER FILE NAME : ");
fname=in.readLine();
dos.writeUTF(fname);
readval=dis.readUTF();
System.out.println("\n"+readval);
skt.close();
}
}
/*Server.java*/
import java.io.*;
import java.net.*;
class server
{
public static void main(String args[]) throws Exception
{
String fname=null;
String data="";
ServerSocket sskt=new ServerSocket(1900);
System.out.println("\nSERVER STARTED ...");
Socket skt=sskt.accept();
InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
DataInputStream dis=new DataInputStream(is);
DataOutputStream dos=new DataOutputStream(os);
char ch;
int i;
fname=dis.readUTF();
FileInputStream fin=new FileInputStream(fname);
while((i=fin.read())!=-1)
{
ch=(char)i;
data=data+ch;
}
dos.writeUTF(data);
System.out.println("\nRESPONDED SUCCESSFULLY");
}
}
import java.io.*;
import java.net.*;
class client
{
public static void main(String args[]) throws Exception
{
String fname=null;
String readval=null;
Socket skt=new Socket("192.168.4.93",1900);//host and port number
InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
DataInputStream dis=new DataInputStream(is);
DataOutputStream dos=new DataOutputStream(os);
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nENTER FILE NAME : ");
fname=in.readLine();
dos.writeUTF(fname);
readval=dis.readUTF();
System.out.println("\n"+readval);
skt.close();
}
}
/*Server.java*/
import java.io.*;
import java.net.*;
class server
{
public static void main(String args[]) throws Exception
{
String fname=null;
String data="";
ServerSocket sskt=new ServerSocket(1900);
System.out.println("\nSERVER STARTED ...");
Socket skt=sskt.accept();
InputStream is=skt.getInputStream();
OutputStream os=skt.getOutputStream();
DataInputStream dis=new DataInputStream(is);
DataOutputStream dos=new DataOutputStream(os);
char ch;
int i;
fname=dis.readUTF();
FileInputStream fin=new FileInputStream(fname);
while((i=fin.read())!=-1)
{
ch=(char)i;
data=data+ch;
}
dos.writeUTF(data);
System.out.println("\nRESPONDED SUCCESSFULLY");
}
}
No comments:
Post a Comment