- import java.net.*;
- import java.io.*;
- class TextClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.168.1.232",2012);
- BufferedReader bufr = new BufferedReader(new FileReader("abc.java"));
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- DataOutputStream dos = new DataOutputStream(s.getOutputStream());
- long time= System.currentTimeMillis();
- dos.writeLong(time);
- String line =null;
- while((line=bufr.readLine())!=null)
- {
- out.println(line);
- }
- dos.writeLong(time);
- //s.shutdownOutput();//关闭客户端的输出流,相当于给流中加结束标记
- BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
- String str = bufIn.readLine();
- System.out.println(str);
- bufr.close();
- s.close();
- }
- }
- class TextServer
- {
- public static void main(String [] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(2012);
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip+"----connected!");
- DataInputStream dis = new DataInputStream(s.getInputStream());
- long l= dis.readLong();
- BufferedReader bufr= new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter out = new PrintWriter(new FileWriter("server.txt"),true);
- String line=null;
- while((line=bufr.readLine())!=null)
- {
- out.println(line);
- }
- PrintWriter pw = new PrintWriter(s.getOutputStream(),true);
- pw.println("上传成功!");
- out.close();
- s.close();
- ss.close();
- }
- }
复制代码 用时间戳在服务端是怎么做的呢? |
|