public void _run() {
try {
final InputStream is = new BufferedInputStream(socket.getInputStream());
+ final OutputStream os = socket.getOutputStream();
+ final OutputStream fos = sp.getOutputStream();
+ final InputStream fis = new BufferedInputStream(sp.getInputStream());
+
+ // read login string
byte[] buf = new byte[1024];
StringBuffer sb = new StringBuffer();
while(true) {
}
System.err.println("login string: " + sb.toString());
if (!sb.toString().startsWith(pass_string)) return;
- final OutputStream os = new BufferedOutputStream(socket.getOutputStream());
-
- final OutputStream fos = sp.getOutputStream();
- final InputStream fis = new BufferedInputStream(sp.getInputStream());
-
- final Semaphore sem = new Semaphore(15);
System.err.println("sending instructions...");
new Thread() {
if (r == -1) break;
synchronized(fos) {
fos.write(r);
+ if (is.available()==0) fos.flush();
}
}
- fos.flush();
+ synchronized(fos) {
+ fos.flush();
+ }
} catch (Exception e) { throw new RuntimeException(e);
} finally {
System.err.println("closing...");
System.err.println("reading back...");
while(true) {
- long result = 0;
int val = 0;
- boolean hit=false;
for(int i=0; i<6; i++) {
int k = 0;
- while(!closed && fis.available()==0) {
+ while (fis.available()==0) {
if (closed) return;
- k++;
- if (k >= 100) {
- System.err.println("sleep");
- k = 0;
- }
- if (k==10) os.flush();
Thread.sleep(10);
}
- if (closed) { os.flush(); return; }
val = fis.read();
if (val==-1) break;
- if ((val & (1<<6)) == 0) {
+ if ((val & (3<<6)) == 0) {
synchronized(fos) {
fos.write( (1<<6) | 1);
}
}
System.err.println("byte: 0x"+Integer.toString(val & 0xff, 16));
os.write((byte)val);
- result |= ((long)val) << (i * 8);
}
if (val==-1) break;
- System.err.print(result);
- System.err.print(" 0x");
- System.err.print(Long.toString(result, 16));
- System.err.println();
}
os.flush();
System.err.println("done.");
} finally {
try {
System.err.println("closing...");
- /*
- fis.close();
- if (fis != null) fis.close();
- */
} catch (Throwable t) { t.printStackTrace(); }
}
}