hi i'm kind of new to java an i want to copy a file between a simple server and a simple client.
I know how to do the client and the server (using Socket class and ServerSocket), but i dont know how to copy a file. I know how to copy a file in my machine with Input Stream and FileInputStream, but i don't know how to use it over the net.
Server
Code:
import java.net.*;
public class server
{
public static void main(String arg[]) throws IOException
{
int port = 8080;
ServerSocket s = new ServerSocket(port);
try
{
Socket socket = s.accept();
//copy file code here
socket.close();
}
finally
{
s.close();
}
}
}
Client
Code:
import java.net.*;
public class client
{
public static void main(String arg[]) throws IOException
{
InetAddress addr = InetAddress.getByName(null);//because i'm in my pc
Socket socket = new Socket(addr, server.port);
try
{
}
finally
{
socket.close();
}
}
}
If you can provide a simple example it will be very helpful
Thanks in advance for your help.