package com.TCPpractise03;
import java.io.*;
import java.net.Socket;
public class ClientDemo {
public static void main(String[] args) throws IOException {
Socket s = new Socket("192.168.17", 8080);
BufferedReader br = new BufferedReader(new FileReader("day_22\\s.txt"));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
String line;
while((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
}
s.shutdownOutput();
BufferedReader brr = new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println( brr.readLine());
s.close();
br.close();
}
}
package com.TCPpractise03;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerDemo {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(8080);
Socket s = ss.accept();
BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
BufferedWriter bw = new BufferedWriter(new FileWriter("day_22\\sss.txt"));
String line;
while((line=br.readLine())!=null){
bw.write(line);
bw.newLine();
bw.flush();
}
BufferedWriter bww = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
bww.write("上传文件成功");
bww.newLine();
bww.flush();
bw.close();
ss.close();
}
} |
|