Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8391717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:20:02+00:00 2026-06-09T19:20:02+00:00

I am writing a program to interact with the management interface for a piece

  • 0

I am writing a program to interact with the management interface for a piece of equipment over TCP. The problem is, the documentation for the equipment is written in C, while the program I am writing is in C#. My problem is, the documentation specifies

The communication is based upon the C structure-based API buffer

No amount of Googling can seem to point me to this API or how I send a raw structure across TCP. The documentation seems to imply that I should use memcpy to copy the struct to the TCP buffer, but C# doesn’t directly support memcpy. Is there an equivelant method in C# or a different way to accomplish this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:20:04+00:00Added an answer on June 9, 2026 at 7:20 pm

    You could build a .Net version of your C struct, then use marshalling to send a byte array through the network. Here’s an example with the MLocation C struct.

    [StructLayout(LayoutKind.Sequential, Pack = 8)]
    public struct MLocation
    {
        public int x;
        public int y;
    };
    
    public static void Main()
    {
        MLocation test = new MLocation();
    
        // Gets size of struct in bytes
        int structureSize = Marshal.SizeOf(test);
    
        // Builds byte array
        byte[] byteArray = new byte[structureSize];
    
        IntPtr memPtr = IntPtr.Zero;
    
        try
        {
            // Allocate some unmanaged memory
            memPtr = Marshal.AllocHGlobal(structureSize);
    
            // Copy struct to unmanaged memory
            Marshal.StructureToPtr(test, memPtr, true);
    
            // Copies to byte array
            Marshal.Copy(memPtr, byteArray, 0, structureSize);
        }
        finally
        {
            if (memPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(memPtr);
            }
        }
    
        // Now you can send your byte array through TCP
        using (TcpClient client = new TcpClient("host", 8080))
        {
            using (NetworkStream stream = client.GetStream())
            {
                stream.Write(byteArray, 0, byteArray.Length);
            }
        }
    
        Console.ReadLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a client-server application using TCP Sockets. The server is written in
I am writing a program which needs communication between processes. my code: #lang racket
I am writing a program to interact with a linux machine through the serial
I'm writing an android program which must interact with google documents, so I have
Today, while writing a regex to match a prompt output in order to interact
I'm writing program in C++ (for XAMPP communication) and I want to execute command
I have the following problem: I am writing a C++ program that has to
I am writing program in Octave and I encountered a problem, I implemented Gauss-Legandre
Im writing this program in C and Im having a big problem when I
While writing my program I got cannot find symbol message when I tried to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.