Home All Groups Group Topic Archive Search About
Author
27 May 2006 11:13 PM
Ben
I have this data I want to send over the network to the server.  It is
working fine except I don't know how to break up the buffer on the receiving
side.  On the client I am sending "hostname<BREAK>data<EOF>"  The server
receives this packet but how would I break it up?

I usually use structs in C for this but how do structures work in VB2005?  I
can define
structure mydata
hostname as string
data as string
end structure

but how does the server know where the hostname stops and the data begins?
In C I would do something like
struct mydata {
char hostname[32]
char data[1024]
}

I guess what I am asking how do I specify the length of a string?

Thanks,
Ben

Author
28 May 2006 9:18 AM
Göran_Andersson
There are two major differences between a C char[] and a .NET string:

:: A C char[] is a value type, while a .NET string is an object. If you
put two strings in a struct, it will just contain two references (fancy
pointers).

:: A C char[] is an array of byte values, while a .NET string contains
an array of (16 bit) unicode characters.

What you are recieving over the network is probably either an array of
bytes or a string.

If it's array of bytes you need to decode it into a string, using an
Encoding object. For instance the Encoding.ASCII.GetString() method.

To split it up, you just use the Split method of the string class to
split the string on the <BREAK> character that you used between the
values. The result is an array of string.

Ben wrote:
Show quoteHide quote
> I have this data I want to send over the network to the server.  It is
> working fine except I don't know how to break up the buffer on the receiving
> side.  On the client I am sending "hostname<BREAK>data<EOF>"  The server
> receives this packet but how would I break it up?
>
> I usually use structs in C for this but how do structures work in VB2005?  I
> can define
> structure mydata
> hostname as string
> data as string
> end structure
>
> but how does the server know where the hostname stops and the data begins?
> In C I would do something like
> struct mydata {
> char hostname[32]
> char data[1024]
> }
>
> I guess what I am asking how do I specify the length of a string?
>
> Thanks,
> Ben
>
>
Author
28 May 2006 7:03 PM
Ben
Thank you for excellent explanation.  I now understand and have fixed the
problem.

Thanks again,
Ben

Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:Og%23p2ejgGHA.1324@TK2MSFTNGP04.phx.gbl...
> There are two major differences between a C char[] and a .NET string:
>
> :: A C char[] is a value type, while a .NET string is an object. If you
> put two strings in a struct, it will just contain two references (fancy
> pointers).
>
> :: A C char[] is an array of byte values, while a .NET string contains an
> array of (16 bit) unicode characters.
>
> What you are recieving over the network is probably either an array of
> bytes or a string.
>
> If it's array of bytes you need to decode it into a string, using an
> Encoding object. For instance the Encoding.ASCII.GetString() method.
>
> To split it up, you just use the Split method of the string class to split
> the string on the <BREAK> character that you used between the values. The
> result is an array of string.
>
> Ben wrote:
>> I have this data I want to send over the network to the server.  It is
>> working fine except I don't know how to break up the buffer on the
>> receiving side.  On the client I am sending "hostname<BREAK>data<EOF>"
>> The server receives this packet but how would I break it up?
>>
>> I usually use structs in C for this but how do structures work in VB2005?
>> I can define
>> structure mydata
>> hostname as string
>> data as string
>> end structure
>>
>> but how does the server know where the hostname stops and the data
>> begins? In C I would do something like
>> struct mydata {
>> char hostname[32]
>> char data[1024]
>> }
>>
>> I guess what I am asking how do I specify the length of a string?
>>
>> Thanks,
>> Ben