- import java.io.*;
- import java.net.*;
- class TextClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.168.1.101",10006);
- BufferedReader bufr = new BufferedReader(new FileReader("C:\\info.txt"));
- PrintWriter out = new PrintWriter(s.getOutputStream(),true);
- DataOutputStream dos = new DataOutputStream(s.getOutputStream());//不合传输的文件的数据流混在一起
- long time = System.currentTimeMillis();
- dos.writeLong(time);
- System.out.println("第一次"+time);
- String line = null;
- while((line = bufr.readLine()) != null)
- {
- out.println(line);
- }
- dos.writeLong(time);
- System.out.println("第二次"+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(10006);
- Socket s =ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip+"客户端连接");
- BufferedReader bufIn = new BufferedReader(new InputStreamReader(s.getInputStream()));
- PrintWriter out = new PrintWriter(new FileWriter("C:\\whataup.txt"),true);
- //接收时间戳标记
- DataInputStream dis = new DataInputStream(s.getInputStream());
- long l = dis.readLong();
- System.out.println("服务端第一次"+l);
- String line = null;
- while((line = bufIn.readLine()) != null )
- {
- /*时间戳标记判断结束*/
- out.println(line);
- }
- PrintWriter feedback = new PrintWriter(s.getOutputStream(),true);
-
- feedback.println("上传成功");
- dis.close();
- out.close();
- s.close();
- }
- }
- 对于用时间戳来结束服务器端的语句,那个判断语句我一直写不对,有人能帮忙不?
复制代码 |