If anybody could help me meet this coursework deadline with a working system, i would be SINCERLY greatful. I have created client side and server side applications. I know how to send text through the socket but how in the world do i send files, ie. .doc files, that exist on the client harddisk??? Can i send it through a fileoutputstream? If anyone could show me some code, i'd be greatful cause i've been searching all over the net with no success...Thanks!
------------------------------------------------------- clie nt side ------------------------------------------------------- public static void main(String args[]){
System.out.println("Establishing connection...");
try {
Socket socket; socket = new Socket("127.0.0.1", 1287);
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
------------------ ------------------------------------- Server side ------------------------------------------------------- public static void main(String[] args ) {
System.out.println("Listening for clientconnection");
try {
ServerSocket socket = new ServerSocket(1287); Socket insocket = socket.accept(); BufferedReader input = new BufferedReader(new InputStreamReader(insocket.getInputStream())); PrintWriter output = new PrintWriter(insocket.getOutputStream(), true);
Just read a little bit hte Docs and you will notice that you can easily have a code like :
Socket s = new Socket(...);
File f = new File(...);
BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
out.write(f);
out.flush();
s.close();