Changeset 565 for trunk


Ignore:
Timestamp:
Jan 17, 2007 2:29:31 PM (17 years ago)
Author:
kennell
Message:

Added a "connect" parameter to forward connection through port router.
Added a snooze() method to sleep.
Changed reconnect logic to handle reconnects after host app exits.
Modified file load to use https if connect parameter is specified.

Location:
trunk/gui/filexfer
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/filexfer/filexfer.java

    r171 r565  
    4545            cookie = "<missing>";
    4646
     47        String connect_param = null;
     48        connect_param = getParameter("connect");
     49
    4750        String ipAddr = "";
    4851        try {
     
    7275
    7376        mon = new monitor(this, getCodeBase().getHost(), port,
    74             user, ipAddr, cookie);
     77            user, ipAddr, cookie, connect_param);
    7578        mon.start();
    7679    }
  • trunk/gui/filexfer/monitor.java

    r213 r565  
    2727    private String ipAddr;
    2828    private String cookie;
     29    private String connect_param;
    2930
    3031    private Socket socket = null;
     
    3536
    3637    public monitor(filexfer parent, String hostName, int hostPort,
    37           String user, String ipAddr, String cookie) {
     38          String user, String ipAddr, String cookie, String connect_param) {
    3839        this.parent = parent;
    3940        this.hostName = hostName;
     
    4243        this.ipAddr = ipAddr;
    4344        this.cookie = cookie;
     45        this.connect_param = connect_param;
     46    }
     47
     48    private void snooze(int sec) {
     49        int ms = sec * 1000;
     50        parent.status.append("Snoozing " + Integer.toString(sec) + " sec.\n");
     51        try {
     52            // sleep a little, so we don't chew up CPU
     53            sleep(ms);
     54        }
     55        catch (java.lang.InterruptedException e) {
     56            // just move on
     57        }
    4458    }
    4559
     
    4963            if (socket == null) {
    5064                if (!connect()) {
    51                     try {
    52                         // sleep a little, so we don't chew up CPU
    53                         sleep(5000);
    54                     }
    55                     catch (java.lang.InterruptedException e) {
    56                         // just move on
    57                     }
     65                    snooze(60);
    5866                }
    5967            } else {
    6068                try {
    61                     line = istream.readLine();
    62                     if (line == null) {
    63                         parent.status.append("CLOSED\n");
    64                         socket.close();
    65                         socket = null;
    66                     } else {
    67                         handle(line);
     69                    while(true) {
     70                        line = istream.readLine();
     71                        if (line == null) {
     72                            parent.status.append("CLOSED\n");
     73                            socket.close();
     74                            socket = null;
     75                        } else {
     76                            handle(line);
     77                        }
    6878                    }
    6979                }
    7080                catch (java.io.IOException e){
    7181                    parent.status.append("I/O error: "+e.getMessage()+"\n");
     82                    try {
     83                        socket.close();
     84                    }
     85                    catch (Exception e2) {
     86                        // Ignore errors.
     87                    }
     88                    socket = null;
    7289                }
    7390                catch (Exception e) {
    7491                    parent.status.append("Internal error: "+e.getMessage()+"\n");
    75                 }
     92                    try {
     93                        socket.close();
     94                    }
     95                    catch (Exception e2) {
     96                        // Ignore errors.
     97                    }
     98                    socket = null;
     99                }
     100                snooze(60);
    76101            }
    77102        }
     
    137162        }
    138163
     164        if (connect_param != null) {
     165            try {
     166                ostream.println("CONNECT " + connect_param + " HTTP/1.1");
     167                ostream.println("Host: " + connect_param);
     168                ostream.println("");
     169            }
     170            catch (Exception e) {
     171                parent.status.append("\nCan't forward connection.");
     172                return false;
     173            }
     174            try {
     175                while(true) {
     176                    String line = istream.readLine();
     177                    if (line.length() == 0) {
     178                        parent.status.append("\nDone with forward.");
     179                        break;
     180                    }
     181                    if (line == null) {
     182                        parent.status.append("\nNull forward.");
     183                        break;
     184                    }
     185                    parent.status.append("\n" + Integer.toString(line.length()) + ":" + line);
     186                }
     187            }
     188            catch (Exception e) {
     189                parent.status.append("\nCan't get forward response.");
     190                return false;
     191            }
     192        }
     193
    139194        try {
    140195            ostream.println("REGISTER "+user+" "+ipAddr+" "+cookie+" RAPPTURE/"+protocol);
     
    144199        catch (Exception e) {
    145200            parent.status.append("\nCan't talk to server");
     201            return false;
    146202        }
    147203        return true;
     
    153209        if (line.startsWith("url ")) {
    154210            try {
    155                 URL url = new URL("http",
    156                     hostName, hostPort, line.substring(4));
     211                URL url = null;
     212                if (connect_param == null) {
     213                    url = new URL("http",
     214                                  hostName, hostPort, line.substring(4));
     215                } else {
     216                    url = new URL("https", hostName,
     217                                  "/" + connect_param.replace(':','/') +
     218                                  line.substring(4));
     219                }
    157220
    158221                try {
Note: See TracChangeset for help on using the changeset viewer.