1 16 package net.sf.jftp.util; 17 18 import net.sf.jftp.*; 19 import net.sf.jftp.config.*; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.net.*; 22 import net.sf.jftp.util.*; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 27 import java.io.*; 28 29 import java.net.*; 30 31 import java.util.*; 32 33 import javax.swing.*; 34 import javax.swing.event.*; 35 36 37 40 public class JRawConnection implements Runnable 41 { 42 private int timeout = Settings.connectionTimeout; 43 private String host; 44 private int port; 45 private PrintStream out; 46 private DataInputStream in; 47 private Socket s; 48 private JReciever jrcv; 49 private boolean isOk = false; 50 private boolean established = false; 51 private boolean reciever = false; 52 private Thread runner; 53 54 public JRawConnection(String host, int port) 55 { 56 this(host, port, false); 57 } 58 59 public JRawConnection(String host, int port, boolean reciever) 60 { 61 this.host = host; 62 this.port = port; 63 this.reciever = reciever; 64 65 runner = new Thread (this); 66 runner.start(); 67 } 68 69 public void run() 70 { 71 try 72 { 73 s = new Socket(host, port); 74 75 out = new PrintStream(s.getOutputStream()); 77 in = new DataInputStream(s.getInputStream()); 78 79 if(reciever) 80 { 81 JReciever jrcv = new JReciever(in); 82 } 83 84 isOk = true; 85 } 86 catch(Exception ex) 87 { 88 isOk = false; 89 } 90 91 established = true; 92 } 93 94 public boolean isThere() 95 { 96 int cnt = 0; 97 98 while(!established && (cnt < timeout)) 99 { 100 pause(100); 101 cnt = cnt + 100; 102 } 103 104 return isOk; 105 } 106 107 public void send(String data) 108 { 109 try 110 { 111 out.println(data); 112 } 113 catch(Exception ex) 114 { 115 System.out.println(ex + "@JConnection.send()"); 116 } 117 } 118 119 public PrintStream getInetOutputStream() 120 { 121 return out; 122 } 123 124 public DataInputStream getInetInputStream() 125 { 126 return in; 127 } 128 129 private void pause(int time) 130 { 131 try 132 { 133 Thread.sleep(time); 134 } 135 catch(Exception ex) 136 { 137 System.out.println(ex); 138 } 139 } 140 } 141 | Popular Tags |