Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
ReaperUnreal
Feb 21, 2007
Trogdor is King
I feel like strangling Java right now, so to keep myself away from the police I will ask here. I'm no stranger to Java, on my 5th year of my 4 year comp-sci program I know it front and back. Somehow though, Sockets seem to be destroying me right now and I have no idea why. It seems that the order in which I create the input/output streams from a socket may or may not break the program. Here's what I mean,

code:
// create the output and input streams
dos = new DeflaterOutputStream(client.getOutputStream(), new Deflater(Deflater.BEST_COMPRESSION));
oos = new ObjectOutputStream(dos);

// send the scene
oos.writeObject(scene);

// send the render size
oos.writeObject(renderSize);

// send the render coordinates
oos.writeObject(workPool.poll());
dos.finish();

// get the render surface
ois = new ObjectInputStream(new InflaterInputStream(client.getInputStream()));
RenderSurface rs = (RenderSurface) (ois.readObject());

// get the render coordinates
RenderCoords rc = (RenderCoords) (ois.readObject());
This works fine.

code:
// create the output and input streams
dos = new DeflaterOutputStream(client.getOutputStream(), new Deflater(Deflater.BEST_COMPRESSION));
oos = new ObjectOutputStream(dos);
ois = new ObjectInputStream(new InflaterInputStream(client.getInputStream()));

// send the scene
oos.writeObject(scene);

// send the render size
oos.writeObject(renderSize);

// send the render coordinates
oos.writeObject(workPool.poll());
dos.finish();

// get the render surface
RenderSurface rs = (RenderSurface) (ois.readObject());

// get the render coordinates
RenderCoords rc = (RenderCoords) (ois.readObject());
This however hangs on the line that creates the ObjectInputStream, and I have no idea why. The java doc is of no help, so I'm hoping that someone here has encountered this before. It's becoming REALLY annoying, and I'm considering switching everything over to CORBA or JavaSpaces despite the work, just because this is being so annoying. Oh btw, this code is inside the run() method of a Runnable object.

Adbot
ADBOT LOVES YOU

ReaperUnreal
Feb 21, 2007
Trogdor is King

zootm posted:

ObjectInputStream(java.io.InputStream)

You're causing deadlock by waiting for input before it's been produced in the same thread.

Huh, how did I not see that? Thanks for the help, looks like I'll be reorganizing things. This'll be fun, having to create input and output streams inside a loop. Honestly, some times, I wish I was using C instead of Java.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply