sending data over tcp
-
hello.. i have to send data i mean collection of5 string variables over the tcp connection using a socket. but the problem is that each time i have to ecode the string to byte and send. can i send all the strings as a collection of bytes or array and decode the sequence at the destination i.e the rciever... thans for any advices.... bye
-
hello.. i have to send data i mean collection of5 string variables over the tcp connection using a socket. but the problem is that each time i have to ecode the string to byte and send. can i send all the strings as a collection of bytes or array and decode the sequence at the destination i.e the rciever... thans for any advices.... bye
Yes, you can use the Encoding.GetBytes[^] method for encoding the strings into bytes, then you can use Encoding.GetString[^] at the destination to decode the bytes into strings. Edit: Sorry, I misread your post. What you want to do is to collect all strings, convert them into bytes and send them all at the same time - then decode them at the receiver. Let's say you have an array with the strings - use a StringBuilder and a foreach loop to build the strings into one big string. Remember to apply a seperator after each string:
builder.Append(theString + seperator);
The strings would then come out as (assuming semi-colon ( ; ) is the seperator): hello;goodbye;hi; At the receiver application you would then split the string (after decoding it of course) into an array to get each string. I hope you could understand what I tried to say, otherwise ask.
:bob: Kristian Sixhoej "You can always become better." - Tiger Woods
modified on Wednesday, February 18, 2009 10:37 AM
-
Yes, you can use the Encoding.GetBytes[^] method for encoding the strings into bytes, then you can use Encoding.GetString[^] at the destination to decode the bytes into strings. Edit: Sorry, I misread your post. What you want to do is to collect all strings, convert them into bytes and send them all at the same time - then decode them at the receiver. Let's say you have an array with the strings - use a StringBuilder and a foreach loop to build the strings into one big string. Remember to apply a seperator after each string:
builder.Append(theString + seperator);
The strings would then come out as (assuming semi-colon ( ; ) is the seperator): hello;goodbye;hi; At the receiver application you would then split the string (after decoding it of course) into an array to get each string. I hope you could understand what I tried to say, otherwise ask.
:bob: Kristian Sixhoej "You can always become better." - Tiger Woods
modified on Wednesday, February 18, 2009 10:37 AM
that was fine i got it... thank you for the keen interest.... have a gud day..
-
that was fine i got it... thank you for the keen interest.... have a gud day..
You're welcome. :) Good day to you as well.
:bob: Kristian Sixhoej "You can always become better." - Tiger Woods