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. Socket Communications between C++ and C#

Socket Communications between C++ and C#

Scheduled Pinned Locked Moved C#
helpquestioncsharpc++sysadmin
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.
  • J Offline
    J Offline
    Jason Douglas
    wrote on last edited by
    #1

    I'm having a very difficult time figuring out what should be a simple problem. I have a server application developed using C++ (on Linux, so it's not being ported to C# any time soon) that sends and receives standard structures over a socket. How can I read those structures, interpret them as attributes, and send a sensible reply? :confused: I've been experimenting with serializing classes with a binary formatter, accessing raw memory, and just creating a plain structure, but could find no way to send the bytes through the socket... Thanks for your help, Jason

    J 1 Reply Last reply
    0
    • J Jason Douglas

      I'm having a very difficult time figuring out what should be a simple problem. I have a server application developed using C++ (on Linux, so it's not being ported to C# any time soon) that sends and receives standard structures over a socket. How can I read those structures, interpret them as attributes, and send a sensible reply? :confused: I've been experimenting with serializing classes with a binary formatter, accessing raw memory, and just creating a plain structure, but could find no way to send the bytes through the socket... Thanks for your help, Jason

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      When you serialize a class extra data is written to tell the runtime what type of object is being serialized. I have no idea if MS put this functionality in but you can look to see if you can work something up between the StructLayout attribute (normally set to Sequential) and the MarshalAs attribute. Then try getting a byte[] array with that data. I just thought of a hack that might work; create a struct, with the first and last elements being an int containing magic numbers; serialize the data to a MemoryStream, then retrieve the bytes from it, using only the data between your magic numbers to send across the wire. Like I said its a hack, and its entirely dependent on how the binary formatter serializes data (assuming it serializes the data in the same order it is in your struct). James Sonork ID: 100.11138 - Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

      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