/*
TCP 复制文件
*/
import java.net.*;
import java.io.*;
class TextClient { //客户端
public static void main(String[] args) throws Exception {
Socket s = new Socket("172.16.41.154", 10003);
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
BufferedReader bufr = new BufferedReader(new FileReader("IPDemo01.java"));
PrintWriter pw = new PrintWriter(out, true);
String line = null;
while((line = bufr.readLine()) != null) {
pw.println(line);
}
s.shutdownOutput();
BufferedReader skBufr = new BufferedReader(new InputStreamReader(in));
String str = skBufr.readLine();
System.out.println(str);
s.close();
bufr.close();
}
}
class TextServer { //服务端
public static void main(String[] args) throws Exception {
ServerSocket ss = new ServerSocket(10003);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip + "....connecting");
InputStream in = s.getInputStream();
OutputStream out = s.getOutputStream();
BufferedReader skBufr = new BufferedReader(new InputStreamReader(in));
PrintWriter pw = new PrintWriter(new FileWriter("IPDemo01_copy.txt"), true);
String line = null;
while((line = skBufr.readLine()) != null) {
pw.println(line);
}
//PrintWriter skPw = new PrintWriter(s.getOutputStream(),true);
//skPw.println("上传成功");
BufferedWriter skBufw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
skBufw.write("上传成功");
skBufw.newLine();
skBufw.flush();
}
}
TCP 复制文件
最新推荐文章于 2022-11-03 13:18:28 发布