Client端代码:
public class Client implements Runnable {
private String ip;// 连接IP
private int port;// 连接端口
private String filePath;// 源文件路径
public Client(String ip, int port, String filePath) {
super();
this.ip = ip;
this.port = port;
this.filePath = filePath;
}
@Override
public void run() {
try {
long id = Thread.currentThread().getId();
System.out.println("进程" + id + "上传开始!");
Socket s = new Socket(InetAddress.getByName(ip), port);
FileInputStream fis = new FileInputStream(filePath);
BufferedInputStream bis = new BufferedInputStream(fis);
DataInputStream dis = new DataInputStream(s.getInputStream());
DataOutputStream dos = new DataOutputStream(s.getOutputStream());