Java and C interaction via stdin/stdout

1998-06-17 Thread Richard Hall

I'd like to create a Java GUI for the monopoly game in the bsdgames
package, but I am having trouble getting the Java program to connect to
the C program.  Runtime.getRuntime().exec("/usr/games/monop"); works just
fine, but Process.getInputStream() doesn't seem to work.

Has anyone succeeded at getting a Java program to interact with a C
program via stdin/stdout?  If so, how?  If not, can you explain the
behavior of the following code?  (JDK 1.1.6 and Debian 2.0 libc5, i386)

import java.io.*;
import java.awt.*;

public class Monopoly extends Thread {
  private InputStream in;
  private BufferedWriter out;
  private Process game = null;

  public Monopoly() {
try {
  game = Runtime.getRuntime().exec("/usr/games/monop");
  in = game.getInputStream();
  out = new BufferedWriter(new
OutputStreamWriter(game.getOutputStream()));
  System.out.println(in.available());
}
catch(IOException e) { System.err.println("Program not started"); }
  }

  public static void main(String args[]) {
Monopoly f = new Monopoly();
System.out.println("ready to begin");
f.start();
  }

  public void run() {
InputStreamReader ir = new InputStreamReader(in);
int count = 0;
try {
  while(!(ir.ready())) {
this.yield();
this.sleep(500);
if(count++ > 10) break;
  }
  System.out.println(ir.ready());
  out.write('\n');
  System.out.println(ir.ready());
  out.newLine();
  out.flush();
  System.out.println(ir.ready());
  out.write('3');
  out.newLine();
  System.out.println(ir.ready());
  System.out.println(ir.read());
}
catch(IOException e2) {}
catch(InterruptedException ex) {}
finally { System.out.println("done"); }
  }
}


bash$ /usr/local/jdk1.1.6/bin/java Monopoly
0
ready to begin
false
false
false
false

The program hangs indefinitely here.  Thanks for your time.

Richard Hall
Network Services
University of Tennessee




out of memory

1998-06-17 Thread Richard Hall

I've just begun using JDK1.1.6 on my Debian 2.0.29 machine, and the
compiler often, but not always claims to be out of memory.  top says:

Mem:   14324K av,  14020K used,304K free,   8732K shrd, 92K buff
Swap:  32252K av,  17908K used,  14344K free  3616K cached

The compiler has bailed with close to 1M of RAM free.  The only things
running while this is happening besides a few xterms are X, Netscape, and
XEmacs.  Do I need to add more swap or what?

Richard Hall
Network Services
University of Tennessee




Re: Java Shell

1999-01-03 Thread Richard Hall

I believe that you can compile Java support into your kernel, or perhaps
as a module.  In other words, what you want does exist.  Check into
building a new kernel or using modules.

Richard Hall
Network Services
University of Tennessee



this must be a bug

1998-07-01 Thread Richard Hall

The attached code generates a NullPointerException which I do not
understand, as none of the relevant objects appear to be null.  Any
explanation or work-around would be appreciated. I am using JDK 1.0.2 on a
Debain 2.0 box, libc5.  I need to stick with 1.0.2 for this project so
that 3.0 browsers can run the code. 

Here is the error message produced by the driver program:

bash-2.00$ java ReaderTest 
0
19928
0
java.io.PipedOutputStream@404e8698
java.lang.NullPointerException
at java.io.PipedOutputStream.write(PipedOutputStream.java)
at java.io.OutputStream.write(OutputStream.java)
at seismo.Reader.run(Reader.java:38)

Thanks,

Richard Hall
Network Services
University of Tennessee


import seismo.Reader;
import java.net.MalformedURLException;

public class ReaderTest {

  public static void main(String[] args) {
try {
  Reader r = new Reader("http://pobox.ns.utk.edu/~hall/java/seismo/data/test");
}
catch(MalformedURLException e) { System.out.println("Learn to type"); }
  }

}


package seismo;

import java.io.*;
import java.net.*;

public class Reader extends Thread implements SeismoFeed {
  private PipedOutputStream output;
  private InputStream stream;
  private int compress_factor = 1;
  private boolean compressed = false;
  private boolean simple = false;
  private int total;
  private int MAX = 576000;

  public Reader(URL u) {
try {
  stream = u.openStream();
  output = new PipedOutputStream();
  start();
}
catch(IOException e) { System.err.println("Reader unable to find data"); }
  }

  public Reader(String s) throws MalformedURLException { this(new URL(s)); }

  public void run() {
while(true) {
  byte[] b = null;
  int bite = 0;

  try {
while((bite = stream.available()) > 0) {
  stream.read((b = new byte[bite]));
System.out.println(b[0]);
System.out.println(b.length);
System.out.println(b[b.length - 1]);
System.out.println(output.toString());
  output.write(b);
  total += bite;
}
  }
  catch(IOException e) {
System.err.println("IOException while reading from stream.  Aborting");
die();
  }

  if(total >= MAX) die();
  yield();
}
  }

  public void die() {
try {
  stream.close();
  output.close();
}
catch(IOException e) {}

stream = null;
output = null;
stop();
  }

  public PipedOutputStream getOutput() { return output; }

  public void setCompression(int cf) {
compressed = true;
compress_factor = cf;
  }

  public void noCompression() { compressed = false; }

}



seg fault when running remotely

1999-02-01 Thread Richard Hall

I am trying to run a java application on a remote machine with the control
panel appearing on my hamm 2.0.36 Debian box.  It used to work on a
different, pre-libc6 Debian box.  It presently works on a Solaris machine,
invoking the program via ssh, but when I try to start the program running
via ssh on my Debian machine, I get a core dump.  I know that access to
the X server is not the problem, since I can run xterm in the secure shell
and have a window pop up on my screen.  Can anyone think of what might be
causing the problem?

Here's the guts:

bash$ /usr/local/java/bin/java ChatServer 6119
SIGSEGV   11*  segmentation violation
si_signo [11]: SIGSEGV   11*  segmentation violation
si_errno [0]: Error 0
si_code [1]: SEGV_ACCERR [addr: 0xdf406197]
 
stackbase=DC9C, stackpointer=DFFFCB90
 
Full thread dump:
"Finalizer thread" (TID:0xde3003b0, sys_thread_t:0xdf460de0) prio=1
"Async Garbage Collector" (TID:0xde300368, sys_thread_t:0xdf490de0)
prio=1
"Idle thread" (TID:0xde300320, sys_thread_t:0xdf4c0de0) prio=0
"clock handler" (TID:0xde3001f8, sys_thread_t:0xdf4f0de0) prio=11
"main" (TID:0xde3000a0, sys_thread_t:0x76de8) prio=5 *current thread*
sun.awt.motif.MToolkit.(MToolkit.java:41)
java.awt.Toolkit.getDefaultToolkit(Toolkit.java:191)
java.awt.Window.getToolkit(Window.java:155)
java.awt.Frame.addNotify(Frame.java:82)
java.awt.Window.show(Window.java:106)
ControlPanel.(ChatServer.java:346)
ChatServer.(ChatServer.java:66)
ChatServer.main(ChatServer.java:104)
Monitor Cache Dump:
unknown key (key=0xdf490de0): unowned
Waiting to be notified:
"Async Garbage Collector"
ControlPanel@DE3010F8/DE33CC78 (key=0xde3010f8): monitor owner:
"main"
sun.awt.motif.MToolkit@DE301348/DE33D5F8 (key=0xde301348): monitor
owner: "main"
java.lang.Class@DE3012A8/9BF28 (key=0xde3012a8): monitor owner:
"main"
Registered Monitor Dump:
Finalize me queue lock: unowned
Waiting to be notified:
"Finalizer thread"
Thread queue lock: unowned
Class lock: unowned
Java stack lock: unowned
Code rewrite lock: unowned
Heap lock: unowned
Has finalization queue lock: unowned
Monitor IO lock: unowned
Child death monitor: unowned
Event monitor: unowned
I/O monitor: unowned
Alarm monitor: unowned
Waiting to be notified:
"clock handler"
Sbrk lock: unowned
Monitor cache lock: unowned
Monitor registry: monitor owner: "main"
Thread Alarm Q:
sys_thread_t 0xdf490de0   [Timeout in 66 ms]
Abort (core dumped)


Thanks for any ideas,

Richard Hall
Network Services
University of Tennessee



Re: Weird math calculations.

1999-02-04 Thread Richard Hall

The problem is that you are using the same VectorUtil object as the source
and destination of your calculations.  You need to either alter the
cross() method so that it returns the cross product calculation, ie. u =
u.cross(v); or you need to create temporary doubles in the cross() method
to store the initial values of u, then use those values in the computation
of the cross product.

As it is, you are computing u.x in the first line of your method, then
usingthat recently changed u.x value to compute u.y, when you really need
to use the original value of u.x.

I hope this makes sense.  I couldn't get the attached code into this reply
easily, but if I haven't made myself clear, ask again, and I'll go through
the slight inconvenience of editing the code.

Your lazy helper,

Richard Hall
Network Services
University of Tennessee



Re: Making an Java Application "wait" to be called

1999-02-18 Thread Richard Hall

I'm just going to give you a partial answer, since it's all I am capable
of.  I think that you probably want to make your application event driven
so that requests come in the form of passed events, then the app just sits
there waiting for events.  Alternately, if it is a server, I think that
you can leave it in ServerSocket.accept(), and it will just wait for
connections without consuming cycles.

I haven't quite figured out what keeps an app from exiting.  It seems that
if you don't put a return; at the end of the main() method, it will sit
idly.  Maybe someone else can give a definitive answer.


Richard Hall
Network Services
University of Tennessee



BDK 1.0

1999-05-13 Thread Richard Hall

Does anyone know where I can download BDK 1.0?  Sun seems to have
completely migrated their site to 1.1, which only works with JDK 1.2.  I
need a version that works with JDK 1.1.  Thanks.

Richard Hall
Network Services
University of Tennessee


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Re: Modal JDialog never returns (Bug?)

1999-06-29 Thread Richard Hall

Hmmm.  I have an applet that also exhibits this same sort of
every-other-click misbehavior, but I don't use any Swing classes.  I get
the error in both the 1.1.7 and 1.0.2 versions of the applet.  Perhaps
it's a bug lurking in the underlying AWT threads?

Richard Hall
Network Services
University of Tennessee



--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]