Forums Register Login

urgent

+Pie Number of slices to send: Send
i am running these two client server programmes on local machine.Actually i want to send a request from client that send me(file name) file so server will send this file to client without open it.File is on local machine and the size of file is 1 MB.So plz update both code for this requirment.Thankz in advance
thats my client programme
------------------------------------------------------------------------
import java.net.*;
import java.io.*;
import java.util.*;
public class Client2{
public static void main(String[] args){
String server="localhost";
int port=80;
try{
Socket socket=new Socket(server,port);
BufferedReader inputStream=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter outputStream=new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
outputStream.println("I need a file named atif.txt");
System.out.println(inputStream.readLine());
socket.close();
}catch(ConnectException e){System.out.println(e);}
catch(UnknownHostException e){System.out.println(e);}
catch(IOException e){System.out.println(e);}
}
}
------------------------------------------------------------------
thats my server programme
--------------------------------------------------------------
import java.net.*;
import java.io.*;
import java.util.*;
public class Server2 {
public static void main(String[] args) {
Socket client;
PrintWriter outputStream;
BufferedReader inputStream;
try
{
ServerSocket server = new ServerSocket(80);
System.out.println("Server listening on port 80");
client = server.accept();
inputStream = new BufferedReader(new InputStreamReader(client.getInputStream()));
outputStream = new PrintWriter(client.getOutputStream(),true);
while(true)
{
String request = inputStream.readLine();
System.out.println("Client says:" + request);
String reply = "Ya i have this file";
outputStream.println(reply );
DataInputStream input=new DataInputStream(new FileInputStream("atif.txt"));
String s=input.toString();
outputStream.println(s);
client.close();
}
}catch(IOException e)
{
System.out.println(e);
}
}
}
----------------------------------------------------------------
Actually this programme send only text line
+Pie Number of slices to send: Send
Posted and answered in this thread
I will open the floodgates of his own worst nightmare! All in a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1556 times.
Similar Threads
a big problem
sending email
i am in trouble
Multithread-call center support
How to send a message back from Server to Client?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:51:05.