Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Re: Reading a NetworkStream

Reply
 
Old 06-11-2008   #1 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Reading a NetworkStream

Peter Bradley <p.bradley@xxxxxx> wrote:
Quote:

> I wonder if anyone can help me out?
>
> I'm trying to implement an EPP (rfc4934 and rfc4930) client. So far
> I've managed to connect and authorise using an X509 Certificate. This
> should elicit a <greeting> response from the server, and it's the
> reading of this response that is giving me a bit of grief.
Is there a public server we can easily contact to try this out?

Note that in RFC 4934 I can't see anything suggesting it will be in
ASCII - just that it's XML. Might it be UTF-16 encoding?

Using BitConverter directly is definitely a bad idea - the RFC says it
will be in big endian format. I have an EndianBitConverter which lets
you specify endianness as part of MiscUtil:
http://pobox.com/~skeet/csharp/miscutil

But yes, that number looks rather large.

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com

My System SpecsSystem Spec
Old 06-11-2008   #2 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Reading a NetworkStream

Peter Bradley <p.bradley@xxxxxx> wrote:
Quote:
Quote:

> > Is there a public server we can easily contact to try this out?
>
> I forgot you'd need a certificate in order to connect to the server. If
> that's a problem I'll see if I can get permission to supply you with the
> certificate I've been using.
I haven't been able to look at the problem tonight, I'm afraid - but if
you could get me the certificate, I'll try to take a look tomorrow.

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Old 06-12-2008   #3 (permalink)
Peter Bradley


 
 

Re: Reading a NetworkStream

Jon Skeet [C# MVP] wrote:
Quote:

>
> I haven't been able to look at the problem tonight, I'm afraid - but if
> you could get me the certificate, I'll try to take a look tomorrow.
>
No problem, Jon. I'm very grateful to you for looking at it at all.

I'll try to get the certificate to you tonight (say in about 9 or 10 hours).

I'm sure it's my stream reading code that's up the spout. This is the
first time I've written code like this. Usually I'm doing business
rules or Active Directory coding in .NET remote objects or Web services.
So I may well be making some really elementary mistakes.

Cheers


Peter
My System SpecsSystem Spec
Old 06-12-2008   #4 (permalink)
Peter Bradley


 
 

Re: Reading a NetworkStream

Jon Skeet [C# MVP] wrote:
Quote:

>
> I haven't been able to look at the problem tonight, I'm afraid - but if
> you could get me the certificate, I'll try to take a look tomorrow.
>
Jon,

I had an epiphany moment. I think I know what the problem is. I'm
reading the response from the server using the NetworkStream associated
with the TcpClient. That's fine, except that this is a secure stream
using SSL, so what I'm looking at is the encrypted data. What I need to
do is to create an SslStream from the Network stream and then read from
that:


// Read the response from the server
int bytesRead = sslStream.Read(buffer, 0, buffer.Length);

// Convert the received bytes into a string

string response = System.Text.Encoding.ASCII.GetString (buffer,
0,
bytes);

OK, so I still have the business of the first 4 bytes to sort out, but
if I'm right on this, that shouldn't be much of a problem.

I'll let you know how I get on.

Thanks


Peter
My System SpecsSystem Spec
Old 06-12-2008   #5 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Reading a NetworkStream

Peter Bradley <pbradley@xxxxxx> wrote:
Quote:

> I had an epiphany moment. I think I know what the problem is. I'm
> reading the response from the server using the NetworkStream associated
> with the TcpClient. That's fine, except that this is a secure stream
> using SSL, so what I'm looking at is the encrypted data.
That would certainly explain it
Quote:

> What I need to
> do is to create an SslStream from the Network stream and then read from
> that:
Right, yes.
Quote:

> // Read the response from the server
> int bytesRead = sslStream.Read(buffer, 0, buffer.Length);
>
> // Convert the received bytes into a string
>
> string response = System.Text.Encoding.ASCII.GetString (buffer,
> 0,
> bytes);
>
> OK, so I still have the business of the first 4 bytes to sort out, but
> if I'm right on this, that shouldn't be much of a problem.
My EndianBitConverter in MiscUtil may well help there.

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Old 06-13-2008   #6 (permalink)
Jon Skeet [C# MVP]


 
 

Re: Reading a NetworkStream

Peter Bradley <p.bradley@xxxxxx> wrote:
Quote:

> Yep. It all works swimmingly now. Amazing how explaining the problem
> to someone else makes you realise what you're messing up.
Absolutely. Occasionally I'll explain something to a colleague who
isn't even listening, and by the time they say, "I'm sorry, were you
talking to me?" I've realised where the problem is
Quote:

> I didn't use your EndianBitConverter in the end. I just checked whether
> we were in little endian context and if so, reversed the byte array.
> Crude, but effective.
Sure.
Quote:

> My grateful thanks for your help - and your sympathetic ear.
>
>
No problem - sorry I couldn't directly actually contribute to speeding
up the solution.

--
Jon Skeet - <skeet@xxxxxx>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
not reading my 120g only reading 24g Drivers
Reading Vista mail
Reading DVD Ram Vista General
reading dvd Vista music pictures video
reading CD-R Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46