2 Replies - 4131 Views - Last Post: 01 December 2009 - 06:00 PM Rate Topic: -----

#1 DecafJava   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 73
  • Joined: 18-May 09

Java printing out strange characters

Posted 01 December 2009 - 04:32 PM

Hi there,

I have a chat program in which two clients connect to each other and can send images back and forth to each other. However, I noticed that after running the program for a little bit and sometimes even very immediately after starting the program (not sure what is the cause), but all of a sudden some strange ASCII characters start to print in the chat area (where it otherwise shows the messages sent back and forth by users). The program also gets affected by users not being able to receive images (sometimes this only happens temporarily then goes away, while other times it keeps printing the junk and causes the program to be unresponsive.

I know it's impossible to tell me EXACTLY how to fix this without seeing any code, but does anyone at least have an idea of what might be causing this?

P.S. I've got some stuff like this in my code:
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocketA.getInputStream()));
PrintWriter out = new PrintWriter(clientSocketA.getOutputStream(), true);
FileInputStream fis = new FileInputStream("UserA.jpg");
byte[] buffer = new byte[fis.available()];
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());

This post has been edited by DecafJava: 01 December 2009 - 04:33 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Java printing out strange characters

#2 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2965
  • View blog
  • Posts: 11,222
  • Joined: 15-July 08

Re: Java printing out strange characters

Posted 01 December 2009 - 05:36 PM

Before sending objects, make sure to clear the buffer add info then send. This process may get rid of any "unwanted" characters.
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java printing out strange characters

Posted 01 December 2009 - 06:00 PM

If you use ObjectOutputStream and ObjectInputStream to not send/read an array of bytes over the wire but send/read the Image object itself
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1