473,693 Members | 2,806 Online
Bytes | Software Development & Data Engineering Community
+ 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.Netwo rkToHostOrder() ?

TIA.

Neil

Feb 18 '06 #1
3 1088
<fa*********@gm ail.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.Netwo rkToHostOrder() ?


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

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

--
Jon Skeet - <sk***@pobox.co m>
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 EndianBitConver ter a try ...

Everyone : tried determining Endianness, then

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

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.Sock ets 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
2138
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, i.e. my html page shows gibberish or I get a server error altogether, which is traced from log file to garbled html code. Has anyone seen this? I wanted to fix this, before I do a complete reinstall of php.
11
1945
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 as well as an O'Reilly one but please I am not a natural C++ programmer so allow me some scope to commit some no-brainers as it were ;)
3
23930
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 ideas on how to convert it into human readable Javascript so I can debug it? sample: \x3E","\x3C/strong\x3E","\x3C/b\x3E","\x3Cem\x3E","\x3Ci\x3E","\x3C/em\x3E","\x3C/i\x3E","\x3Cbody contentEditable=true","\x3Cbody
6
3436
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 now I'm trying an XmlTextWriter instead. I whipped-up another webservice based on this: http://www.codeproject.com/aspnet/RSSviaXmlTextWriter.asp?print=true This example isn't set up strictly as a webservice. It seems to output to an aspx...
4
8656
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 int array byte for example: byte=0xEFBB byte=0xBF0D
36
5302
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 between 0 and 7 (=2^3-1). Could someone please help out? I can assume the largest returned value fits in an int. Also, I'm on a big-endian PPC (AIX), in case that matters. Ideally, I'd like to implement a prototype like: int...
14
2509
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 Code; char pn;
12
13474
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 sprintf(pHex,"%0X",9987967441778573855). But it only returns 8
105
6170
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
8611
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9100
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8815
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6475
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5824
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2989
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 we have to send another system
2
2245
muto222
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.