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. Managed C++/CLI
  4. Sending Native Struct via TCP

Sending Native Struct via TCP

Scheduled Pinned Locked Moved Managed C++/CLI
questioncsharpc++dotnet
2 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.
  • T Offline
    T Offline
    tjkrz
    wrote on last edited by
    #1

    I need to communicate with a non-windows platform via TCP. The message will be a unmanaged data structure. How can I encode this into a managed type that the Socket.Send command can handle? The message must be decoded on the other platform, which won't have the .NET framework.

    M 1 Reply Last reply
    0
    • T tjkrz

      I need to communicate with a non-windows platform via TCP. The message will be a unmanaged data structure. How can I encode this into a managed type that the Socket.Send command can handle? The message must be decoded on the other platform, which won't have the .NET framework.

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      You'd need to create an array of Bytes (for the Socket::Send()) and "serialize" a managed type into a stream of bytes (representing the structure) in the array. A couple things to keep in mind: Structure packing can be different on different languages/platforms.   This means you have to ensure each of the structure's members is at the appropriate offset in the Byte array. The BitConverter class can help for converting managed base types to a stream of byes, but you need to deal with byte order (endian-ness) of multi-byte types if the other platform is different.  If this is an issue, multi-byte integer types sould be sent using network byte order.  IPAddress::HostToNetworkOrder() and IPAddress::NetworkToHostOrder() can do the conversion but the other end needs to know to convert the sent network-order bytes back to host-order. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      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