-
Converting Binary Long to Long (Time Server Client)
I'm writing a time server client in C# and obtaining the Binary long from
the server on port 37, however i'm unsure how to convert that to just a long.
To obtain the value i use StreamReader.ReadToEnd() which returns the value
as a string. I tried Int32.Parse(StreamReader.ReadToEnd()) to obtain the
returned value, but to no success.
Can anyone help?
Regards
Ben Merrills
-
Re: Converting Binary Long to Long (Time Server Client)
That's great! Thanks, one other question, here's the response i get (formatted):
Got response from server 1746526400
Closed Server Connection
New Date/Time: 01 January 0001 00:02:54
Now, as you can see that date is wrong, do I have to reverse the byte order
or something?
Regards
Ben Merrills
Mattias Sjögren <mattias.dont.want.spam@mvps.org> wrote:
>Ben,
>
>>To obtain the value i use StreamReader.ReadToEnd() which returns the value
>>as a string. I tried Int32.Parse(StreamReader.ReadToEnd()) to obtain the
>>returned value, but to no success.
>>
>>Can anyone help?
>
>To read integers ans other binary data, use a BinaryReader (in this
>case its ReadInt32 method) instead of a StreamReader.
>
>
>Mattias
>
>===
>Mattias Sjögren (VB MVP)
>mattias @ mvps.org
>http://www.msjogren.net/dotnet/
-
Re: Converting Binary Long to Long (Time Server Client)
Ben,
>To obtain the value i use StreamReader.ReadToEnd() which returns the value
>as a string. I tried Int32.Parse(StreamReader.ReadToEnd()) to obtain the
>returned value, but to no success.
>
>Can anyone help?
To read integers ans other binary data, use a BinaryReader (in this
case its ReadInt32 method) instead of a StreamReader.
Mattias
===
Mattias Sjögren (VB MVP)
mattias @ mvps.org
http://www.msjogren.net/dotnet/
-
Re: Converting Binary Long to Long (Time Server Client)
Ben,
>Now, as you can see that date is wrong, do I have to reverse the byte order
>or something?
Dunno, that depends on which format the value has in the stream, and
which format you want to have it in.
Mattias
===
Mattias Sjögren (VB MVP)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks