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. Nices way ... Stream!

Nices way ... Stream!

Scheduled Pinned Locked Moved C#
csharpsysadmindata-structures
3 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.
  • D Offline
    D Offline
    Daniel Strigl
    wrote on last edited by
    #1

    Is there a nices way than this:

    System.IO.Stream stream = irdaClient.GetStream();

    int msglength = System.Net.IPAddress.HostToNetworkOrder(textBox1.Text.Length);

    byte[] length = new byte[4];
    length[0] = (byte)((msglength >> 0 ) & 0x000000FF);
    length[1] = (byte)((msglength >> 8 ) & 0x000000FF);
    length[2] = (byte)((msglength >> 16) & 0x000000FF);
    length[3] = (byte)((msglength >> 24) & 0x000000FF);

    stream.Write(length, 0, length.Length);

    I think that the way with the byte array is not very nice! I think it's ugly X|! The stream is a IrDA connection! I have tried the StreamWriter class, but that doesn't work! The Server-Application receives some wrong things! Daniel ;) --------------------------- Never change a running system!

    N 1 Reply Last reply
    0
    • D Daniel Strigl

      Is there a nices way than this:

      System.IO.Stream stream = irdaClient.GetStream();

      int msglength = System.Net.IPAddress.HostToNetworkOrder(textBox1.Text.Length);

      byte[] length = new byte[4];
      length[0] = (byte)((msglength >> 0 ) & 0x000000FF);
      length[1] = (byte)((msglength >> 8 ) & 0x000000FF);
      length[2] = (byte)((msglength >> 16) & 0x000000FF);
      length[3] = (byte)((msglength >> 24) & 0x000000FF);

      stream.Write(length, 0, length.Length);

      I think that the way with the byte array is not very nice! I think it's ugly X|! The stream is a IrDA connection! I have tried the StreamWriter class, but that doesn't work! The Server-Application receives some wrong things! Daniel ;) --------------------------- Never change a running system!

      N Offline
      N Offline
      Nathan Blomquist
      wrote on last edited by
      #2

      If all you are trying to do is put the bytes of the int into the stream, why not use a BinaryWriter? This class has many overloads for Write(). Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

      D 1 Reply Last reply
      0
      • N Nathan Blomquist

        If all you are trying to do is put the bytes of the int into the stream, why not use a BinaryWriter? This class has many overloads for Write(). Hope this helps, Nathan --------------------------- Hmmm... what's a signature?

        D Offline
        D Offline
        Daniel Strigl
        wrote on last edited by
        #3

        Thanks! I will try it! Daniel ;) --------------------------- Never change a running system!

        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