Hey All,
Does java allow multiple OutputStreams to work together?
I'm creating a simple server program that sends an array through
ObjectOutputStream and sends a String through PrintWriter. However,
whenever I create an ObjectOutputStream and try to send data through
PrintWritert, funky characters come out. But when I dont create the
ObjectOutputStream then the message comes through on the client side or
telnet.
Below is the code that works:
import java.net.*;
import java.io.*;
public class Server
{
public static void main(String[] args)
{
int i[] = {1, 2, 3, 4, 5, 6};
try
{
ServerSocket server = new ServerSocket(8008);
Socket client = server.accept();
//ObjectOutputStream o = new
ObjectOutputStream(
// client.getOutputStream());
PrintWriter p = new PrintWriter(newOutputStreamWriter(
client.getOutputStream()));
p.println("Message Test");
o.flush();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
When I put this line in the code, ObjectOutputStream o = new
ObjectOutputStream(client.getOutputStream()); , then a funky character
comes out instead of the text I sent.
To see what I mean you can try this command in dos: telnet localhost
8008
Heiner Kücker - 10 Dec 2005 23:03 GMT
> When I put this line in the code, ObjectOutputStream o = new
> ObjectOutputStream(client.getOutputStream()); , then a funky character
> comes out instead of the text I sent.
The ObjectOutputStream is for srialization Objects,
not for printing strings over the xxxWriter.

Signature
Heiner
www.heinerkuecker.de
Bari - 10 Dec 2005 23:37 GMT
I made a little mistake, I meant to write:
PrintWriter p = new
PrintWriter(newOutputStreamWriter(client.getOutputStream()));
p.println("Message Test");
p.flush();
I want to use 'p' to send Strings over the socket, but I want to use
the ObjectOutputStream to send objects over the socket. However, when I
create an ObjectOuputStream the object 'p' can't even send a corrent
message.
This is the output of the message ¼fTest Message
Alan Krueger - 12 Dec 2005 04:31 GMT
> I made a little mistake, I meant to write:
> PrintWriter p = new
[quoted text clipped - 7 lines]
>
> This is the output of the message ¼fTest Message
Wow, it reverses the order of the words? Or are you typing from memory?
Please copy-and-paste exactly what is being run and exactly what is
being output.