class TextClient {
public static void main(String[] args) throws UnknownHostException, IOException {
Socket s = new Socket("172.19.124.1", 10000);
BufferedReader br = new BufferedReader(new FileReader("Demo.java"));
PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
String line = null;
while ((line = br.readLine()) != null) {
pw.write(line);
}
s.shutdownOutput();
BufferedReader brIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
String str = brIn.readLine();
System.out.println(str);
br.close();
s.close();
}
}
class TextServer {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(10000);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip + "--------");
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
PrintWriter out = new PrintWriter(new FileWriter("Demo_copy.java"), true);
String line = null;
while ((line = br.readLine()) != null) {
out.write(line);
}
PrintWriter pw = new PrintWriter(s.getOutputStream(), true);
pw.write("上传成功");
s.close();
ss.close();
out.close();
}
} |
|