• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

urgent

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Posted and answered in this thread
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic