Re: Object serialization and NetworkStream - extraneous characters in output
From: jwallison (jwallison_at_nospam.net)
Date: 12/17/04
- Next message: Shariq Khan: "Re: How to programmatically retrieving the "Startup Type" for Windows"
- Previous message: PseudoBill: "Disappearing Buttons"
- In reply to: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Next in thread: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Reply: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 17 Dec 2004 14:35:26 -0500
It doesn't just happen in Java, it ALSO happens with .Net -
private const int portNum = 7024;
public static int Main(String[] args)
{
bool done = false;
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpListener listener = new TcpListener(localAddr, portNum);
listener.Start();
while (!done)
{
Console.Write("\nWaiting for connection...");
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Connection accepted.");
NetworkStream ns = client.GetStream();
try
{
byte[] bytes = new byte[2048];
int bytesRead;
while( (bytesRead = ns.Read(bytes, 0, bytes.Length)) > 0)
Console.WriteLine(Encoding.UTF8.GetString(bytes, 0, bytesRead));
ns.Close();
client.Close();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
listener.Stop();
return 0;
}
returns output identical to the Java client (with a leading "?").
"Steven Cheng[MSFT]" <v-schang@online.microsoft.com> wrote in message
news:hreNUjB5EHA.3200@cpmsftngxa10.phx.gbl...
> Hi Jwallison,
>
> Thanks for your followup. I've just done some tests between .net and java.
> Write file in .net and read in java, write in java and read in .net( via
> UTF-8). First, I've found the problem you mentioned, when reading into
java
> stream via UTF-8, an additional "?" occurs. But if I use JAVA to write out
> a utf-8 encoded xml file, I can load it correctly in .net.
>
> I think there is something different of the file's output between .net
and
> java. I'll do some research and have some further test to check this. I'll
> update you if I got some info. Also, if you find any ideas meanwhile,
> please also feel free to post here. Thanks.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Support
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
- Next message: Shariq Khan: "Re: How to programmatically retrieving the "Startup Type" for Windows"
- Previous message: PseudoBill: "Disappearing Buttons"
- In reply to: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Next in thread: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Reply: Steven Cheng[MSFT]: "Re: Object serialization and NetworkStream - extraneous characters in output"
- Messages sorted by: [ date ] [ thread ]