好像路人甲不是给你解决了吗?你的应用逻辑到底是干什么的,说具体一些,我们也好帮忙,你就说一个if modify since,我还是不明白什么意思呀。到底是你们导师给你一个点时间,比如今天18点,然后如果晚于这个时间点的修改,都重新下载的意思吗?你写的长点,自然有人帮忙

解决方案 »

  1.   

    路人甲的东西我看到了,但是不明白是什么意思,我是一点都没有java基础的,只会考书上的例子,然后执行之。其实导师的要求是这样的:1: 用java写一个简单的socket程序,可以从server(windows 2000 IIS做服务器)取一个html的文件回来,把它显示在dos下。2:同时还要显示出http的respone header的信息(一定要包括Expire time和Etag的信息)。(这两个要求我贴出的程序都可以实现了。(不过我的程序是从书上找的,有问题,执行完后不能关闭。why?))**2: 在程序里还要求可以使用http中的If-Modified-Since这个条件,并证明这个条件起了作用。例如:如果在某个特定时间前server端的html被改变过执行完这个程序后,就正常返回那个html的文件,要是在这个时间前html文件没有被改动过server就只返回一个304的代码,表示文件没有被改动过。
    当然还有If-Unmodified-Since,If-Match 和If-None-Match(用于比较Etag里的信息),这些条件都是http中的东西,被要求要和程序中的get request配合使用。我是实在不知道怎么在java socket的程序中使用这些http的条件。
    好了,整个我的project就是这样了,不知道是不是够详细。 要是谁有办法一定要帮帮我,高手们一定应该不会觉得这东西难吧,可是我在澳洲这鬼地方找资料都没有办法,英文又差,要是下个星期再交不了程序就死定了。(这个程序可就是1门课呀,2000澳币呀!)
    我的email是[email protected]    或者[email protected](英文)
      

  2.   

    我给你把程序死的问题解决了,另外的逻辑我把思路写在程序中了import  java.net.*;  
    import  java.io.*;  public class SimpleWebClient {  
    public static void main(String[] args){  
        Socket sock = null;    
    InputStream isIn = null;    
        PrintStream psOut = null;  
        byte abDataIn[] = new byte[1024];  
        int iNumBytes;      try {
         //I make the web server to my localhost,and port 8000
          sock = new Socket("127.0.0.1", 8000);  
          isIn = sock.getInputStream();  
          psOut = new PrintStream(sock.getOutputStream());  
     
          System.out.println("Clnt:  Sending  a  GET  request...");  
          psOut.println("GET /index.html HTTP/1.1");  
          psOut.println("Connection:  Keep-Alive");  
          psOut.println("User-Agent:  Mozilla/2.0GoldB1  (Win95;  I)");  
          psOut.println("Pragma:  no-cache");  
          psOut.println("Host:  localhost");  
          psOut.println("Accept:  image/gif,  image/x-xbitmap,  "  
           + "image/jpeg,  image/pjpeg,  */*");  
          psOut.println  ("");  
          System.out.println("Clnt:  Sent  a  GET  request...\n");  
         
      /*
          while(true){  
            //the program will wait the inputstream to receive the other 1024 bytes
            //if can not get the bytes, the program will freeze util get the bytes
            iNumBytes = isIn.read(abDataIn, 0, 1024);  
            if (iNumBytes < 0) {  
             
              break;  
           }
           System.out.println("-------------Received---------------  "  
             + iNumBytes + "  bytes");  
           System.out.println(new  String  (abDataIn,  0,  0,  iNumBytes));  
          System.out.println("------------------------------------\n");  
         }*/
         while(isIn.available() > 0){
           iNumBytes = isIn.read(abDataIn, 0, 1024);
    /*
    come here you can get the last-modified information
    use this infomation to compare to your given time point, 
    if the last-modified field is later than the time your teacher given
    then return the full response
    else return code 304
    It is too cumbersome to write that code. And because your use socket and inputstream
    instead of Http... class, so I can not use the method Http... Class defined
    I think u can use readLine() method, so u can deal with each Line one by one
    if u find the line with "last-modified", then get the time info
    just so so, good luck to u
    if u can not understand what i said, email to [email protected]
    Good Night 

    ps: the program not can exit with no error
    */

           System.out.println("-------------Received---------------  "  
             + iNumBytes + "  bytes");  
           System.out.println(new  String  (abDataIn,  0,  0,  iNumBytes));  
          System.out.println("------------------------------------\n");  
         }
       } catch (Exception  exception) {  
         System.out.println  ("Clnt:  Exception  interacting  with  socket:  " + exception);  
       } finally {
         try {
           isIn.close();
           psOut.close();
           sock.close();
        }catch(Exception e) {
        e.printStackTrace();
        }
       }
    }
    }  
     
      

  3.   

    to yang_sun: 谢谢了,我给你发了邮件,收到了么?