473,480 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

garbled long value returned from the network

hi all,

im using a C# webservice to communicate some data over a socket to a
VC++ program.

what the vc++ program does is return a struct() over the socket.

now the struct contains 2 32 bit integers (according to VC++) i.e. long
(System.Int32)

all the byte[] data is received correctly, however , if im expecting
'320' as the value of the long variable im getting a huge number like
'612334539'.

does this have something to do with Little-Endian / Big-Endian issues ?
does this require me to use IPAddress.NetworkToHostOrder() ?

TIA.

Neil

Feb 18 '06 #1
3 1077
<fa*********@gmail.com> wrote:
im using a C# webservice to communicate some data over a socket to a
VC++ program.

what the vc++ program does is return a struct() over the socket.

now the struct contains 2 32 bit integers (according to VC++) i.e. long
(System.Int32)
Note that a long may be 32 bits in C (in some compilers anyway) but in
C# an int is 32 bits and a long is 64.
all the byte[] data is received correctly, however , if im expecting
'320' as the value of the long variable im getting a huge number like
'612334539'.

does this have something to do with Little-Endian / Big-Endian issues ?
Sounds like it.
does this require me to use IPAddress.NetworkToHostOrder() ?


No. You can use my EndianBitConverter, available at
http://www.pobox.com/~skeet/csharp/miscutil

That lets you convert in either endianness. (There's an equivalent
EndianBinaryReader/Writer, too.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 18 '06 #2
thank you John, i will try that when i get back on Monday..

the client at the other end is VC++ 6.0 .... running a sizeof() on a
long variable at that end confirms its 32 bits (4 bytes) in length.

my C# program is using System.Int32 , and not 'long' :) thanks for that
heads-up too .... its a common confusion i believe.

have a good weekend, mate.

Feb 18 '06 #3
Jon:have yet to give your EndianBitConverter a try ...

Everyone : tried determining Endianness, then

doing a Array.Reverse() on my byte array and then doing a
BitConverter.ToInt32.

the value that i was getting before turns -/ve.

interesting fact i found out is

(decimal - 10486155, hex - a0018b) {139, 1 , 160 , 0} (which were the
four numbers i was getting in my byte[])

ONLY the last 2 (160, 0 ) is correct .... i have NO clue where the
139,1 is coming from.

i wasnt aware that System.Net.Sockets appends any sort of High-Order
Byte ....

forgive me i've just been thinking of this problem so much i KNOW Im
missing the forest for the trees!!!

TIA

Feb 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2125
by: steve | last post by:
Hi, My Windows machine running PHP Version 4.3.4, Apache, mysql, Zend IDE has developed a strange problem whereas the html code coming out of php sometimes gets garbled in unpredicatable ways,...
11
1925
by: Daniel Wilcox | last post by:
I have a question, I have been given a piece of code that apparantly compiles under Visual C++ but I cannot get to compile under g++ 3.2. I have read the FAQ and delved into the Stroustrup book...
3
23895
by: John Dalberg | last post by:
I have a js file that is encrypted or garbled, See example below. Does it need a decrypter or does Javascript know how to deal with it right off? This js file is causing an error under IE. Any...
6
3425
by: Bruce W.1 | last post by:
The intent of my web service is an RSS feed from a blog. Originally I used a StringBuilder to make the XML and returned a string from the webmethod. But this doesn't display properly in IE. So...
4
8634
by: Lingyun Yang | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** Dear all, I have a file it's binary data viewed in UltraEdit is EF BB BF 0D 0A 3C ....... I want to read them into a int or long...
36
5254
by: Digital Puer | last post by:
Hi, suppose I have an unsigned long long. I would like to extract the front 'n' bits of this value and convert them into an integer. For example, if I extract the first 3 bits, I would get an int...
14
2484
by: Ronodev.Sen | last post by:
i have a C# program that is sending data in a byte array through a socket. the VC++ application server receives data in teh following format.... typedef struct advice { header sHdr; char ...
12
13347
by: Ahmad Jalil Qarshi | last post by:
Hi, I have an integer value which is very long like 9987967441778573855. Now I want to convert it into equivalent Hex value. The result must be 8A9C63784361021F I have used...
105
6070
by: Keith Thompson | last post by:
pereges <Broli00@gmail.comwrites: These types already have perfectly good names already. Why give them new ones? If you must rename them for some reason, use typedefs, not macros. --
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.