Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. sending data over tcp

sending data over tcp

Scheduled Pinned Locked Moved C#
data-structureshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mubeen asim
    wrote on last edited by
    #1

    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

    K 1 Reply Last reply
    0
    • M Mubeen asim

      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

      K Offline
      K Offline
      Kristian Sixhoj
      wrote on last edited by
      #2

      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

      M 1 Reply Last reply
      0
      • K Kristian Sixhoj

        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

        M Offline
        M Offline
        Mubeen asim
        wrote on last edited by
        #3

        that was fine i got it... thank you for the keen interest.... have a gud day..

        K 1 Reply Last reply
        0
        • M Mubeen asim

          that was fine i got it... thank you for the keen interest.... have a gud day..

          K Offline
          K Offline
          Kristian Sixhoj
          wrote on last edited by
          #4

          You're welcome. :) Good day to you as well.

          :bob: Kristian Sixhoej "You can always become better." - Tiger Woods

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups