By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,734 Members | 1,352 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,734 IT Pros & Developers. It's quick & easy.

Sending 4 byte message length header

P: n/a
Hi:

I'm currently developing a socket application and would like to precede the
data being sent with a 4 byte message length header (bin4). Can anyone help

Regards

Winston
Nov 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Winston,

If you have the socket open, what is to prevent you from calling Send on
the socket before the data that you want to send?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Winston Nimchan" <wi*************@trinsys.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
Hi:

I'm currently developing a socket application and would like to precede the data being sent with a 4 byte message length header (bin4). Can anyone help
Regards

Winston

Nov 16 '05 #2

P: n/a
My problem is sending the 4 byte message header. Let me explain with an
example...

I have a 90 bytes array with data and am trying to precede this data with
the length (90) converted to hex then to 4 bytes before sending the data so
preceding my 90 bytes will be
h[0] = 0
h[1] = 0
h[2] = 0
h[3] = 5A

Any idea on how I can accomplish this?

thanks

winston
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ei***************@TK2MSFTNGP10.phx.gbl...
Winston,

If you have the socket open, what is to prevent you from calling Send on the socket before the data that you want to send?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Winston Nimchan" <wi*************@trinsys.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
Hi:

I'm currently developing a socket application and would like to precede

the
data being sent with a 4 byte message length header (bin4). Can anyone

help

Regards

Winston


Nov 16 '05 #3

P: n/a
Winston,

You seem to have this solved already. You know how to convert to a
four-byte array. Once you have that, make a call to Send with the four byte
array. Then make another call to Send, passing the actual data.

If you are sending a four byte unsigned integer, you could always call
the static GetBytes method on the BitConverter class, which will return the
four byte array that you are seeking (if you pass it an unsigned integer).
However, you will have to change the order, by calling the static Reverse
method on the Array class.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Winston Nimchan" <wi*************@trinsys.com> wrote in message
news:ux**************@TK2MSFTNGP09.phx.gbl...
My problem is sending the 4 byte message header. Let me explain with an
example...

I have a 90 bytes array with data and am trying to precede this data with
the length (90) converted to hex then to 4 bytes before sending the data so preceding my 90 bytes will be
h[0] = 0
h[1] = 0
h[2] = 0
h[3] = 5A

Any idea on how I can accomplish this?

thanks

winston
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:ei***************@TK2MSFTNGP10.phx.gbl...
Winston,

If you have the socket open, what is to prevent you from calling Send
on
the socket before the data that you want to send?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Winston Nimchan" <wi*************@trinsys.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
Hi:

I'm currently developing a socket application and would like to

precede the
data being sent with a 4 byte message length header (bin4). Can anyone

help

Regards

Winston



Nov 16 '05 #4

P: n/a
first of all, there is no such thing as converting it to hex. hex is just a
string representation of a bunch of bits. you can't store anything as hex.

there are a number of ways to accomplish what you want.
1. use bitand and shift
2. BitConverter.GetBytes, but you need to reverse the byte array that it
returns
2. unsafe pointer to look at bytes of the int in reverse order

"Winston Nimchan" wrote:
My problem is sending the 4 byte message header. Let me explain with an
example...

I have a 90 bytes array with data and am trying to precede this data with
the length (90) converted to hex then to 4 bytes before sending the data so
preceding my 90 bytes will be
h[0] = 0
h[1] = 0
h[2] = 0
h[3] = 5A

Any idea on how I can accomplish this?

thanks

winston
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ei***************@TK2MSFTNGP10.phx.gbl...
Winston,

If you have the socket open, what is to prevent you from calling Send

on
the socket before the data that you want to send?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Winston Nimchan" <wi*************@trinsys.com> wrote in message
news:Oo**************@TK2MSFTNGP09.phx.gbl...
Hi:

I'm currently developing a socket application and would like to precede

the
data being sent with a 4 byte message length header (bin4). Can anyone

help

Regards

Winston



Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.