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 722917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:02:46+00:00 2026-05-14T06:02:46+00:00

I have a client server application in which I need to transmit a user

  • 0

I have a client server application in which I need to transmit a user defined object from Client to Server using TCP connection. My object is of the following structure:

class Conversation
{
    private string convName, convOwner;
    public ArrayList convUsers;

    public string getConvName()
    {
       return this.convName;
    }
    public string getConvOwner()
    {
       return this.convOwner;
    }
}

Please help me how to transmit this object at from client and again de-serialize it into appropriate object at server side.

  • 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-05-14T06:02:46+00:00Added an answer on May 14, 2026 at 6:02 am

    As answered, you should make your object serializable. Once you did that with the Serializable attribute, you can use the famous BinaryFormatter to convert your object into a byte array.

    You can find many examples out there for using the BinaryFormatter, just use your favorite search engine. Here’s a short example:

    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    
    public class SerializationUtils
    {
        public static byte[] SerializeToByteArray(object request)
        {
            byte[] result;
            BinaryFormatter serializer = new BinaryFormatter();
            using (MemoryStream memStream = new MemoryStream())
            {
                serializer.Serialize(memStream, request);
                result = memStream.GetBuffer();
            }
            return result;
        }
    
        public static T DeserializeFromByteArray<T>(byte[] buffer)
        {
            BinaryFormatter deserializer = new BinaryFormatter();
            using (MemoryStream memStream = new MemoryStream(buffer))
            {
                object newobj = deserializer.Deserialize(memStream);
                return (T)newobj;
            }
        }
    }
    

    As for your class, it includes two private fields. I can’t see where you set values for them, so I changed your code a bit, so that they can be set in the constructor. In addition, I added the needed Serializable attribute:

    using System;
    using System.Collections;
    
    [Serializable]
    public class Conversation
    {
        public Conversation(string convName, string convOwner)
        {
            this.convName = convName;
            this.convOwner = convOwner;
        }
    
        public Conversation()
        {
        }
    
        private string convName, convOwner;
        public ArrayList convUsers;
    
        public string getConvName()
        {
            return this.convName;
        }
        public string getConvOwner()
        {
            return this.convOwner;
        }
    }
    

    Now let’s put it all together, and see your class serialized and then deserialized, in a Console Application:

    using System;
    using System.Collections;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    
    namespace Capishi
    {
        [Serializable]
        public class Conversation
        {
            public Conversation(string convName, string convOwner)
            {
                this.convName = convName;
                this.convOwner = convOwner;
            }
    
            public Conversation()
            {
            }
    
            private string convName, convOwner;
            public ArrayList convUsers;
    
            public string getConvName()
            {
                return this.convName;
            }
            public string getConvOwner()
            {
                return this.convOwner;
            }
        }
    
        public class SerializationUtils
        {
            public static byte[] SerializeToByteArray(object request)
            {
                byte[] result;
                BinaryFormatter serializer = new BinaryFormatter();
                using (MemoryStream memStream = new MemoryStream())
                {
                    serializer.Serialize(memStream, request);
                    result = memStream.GetBuffer();
                }
                return result;
            }
    
            public static T DeserializeFromByteArray<T>(byte[] buffer)
            {
                BinaryFormatter deserializer = new BinaryFormatter();
                using (MemoryStream memStream = new MemoryStream(buffer))
                {
                    object newobj = deserializer.Deserialize(memStream);
                    return (T)newobj;
                }
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                // create and initialize a conversation object
                var convName = "Capishi";
                var convOwner = "Ice Cream";
                Conversation myConversation = new Conversation(convName, convOwner);
                myConversation.convUsers = new ArrayList();
                myConversation.convUsers.Add("Ron Klein");
                myConversation.convUsers.Add("Rakesh K");
    
                // serialize to a byte array
                byte[] data = SerializationUtils.SerializeToByteArray(myConversation);
    
                // print the resulting byte array if you want
                // PrintArray(data);
    
                // deserialize the object (on the other side of the communication
                Conversation otherConversation = SerializationUtils.DeserializeFromByteArray<Conversation>(data);
    
                // let's see if all of the members are really there
                Console.WriteLine("*** start output ***");
                Console.WriteLine("otherConversation.getConvName() = " + otherConversation.getConvName());
                Console.WriteLine("otherConversation.getConvOwner() = " + otherConversation.getConvOwner());
                Console.WriteLine("otherConversation.convUsers:");
                foreach (object item in otherConversation.convUsers)
                {
                    Console.WriteLine(item);
                }
                Console.WriteLine("*** done output ***");
    
                // wait before close
                Console.ReadLine();
    
            }
    
            /// <summary>
            /// just a helper function to dump an array to the console's output
            /// </summary>
            /// <param name="data"></param>
            private static void PrintArray(byte[] data)
            {
                for (int i = 0; i < data.Length; i++)
                {
                    Console.Write("{0:000}", data[i]);
                    if (i < data.Length - 1)
                        Console.Write(", ");
                }
                Console.WriteLine();
            }
        }
    }
    

    The result is:

    *** start output ***
    otherConversation.getConvName() = Capishi
    otherConversation.getConvOwner() = Ice Cream
    otherConversation.convUsers:
    Ron Klein
    Rakesh K
    *** done output ***
    

    And a final note:

    I’d use the generic List instead of the outdated ArrayList, unless you’re bound to .NET 1.*.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 370k
  • Answers 370k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Two more tables will do the magic (below). Hacks like… May 14, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer You can start by adjusting your CSS rules and using… May 14, 2026 at 6:36 pm
  • Editorial Team
    Editorial Team added an answer Just login a user for each test. The best way… May 14, 2026 at 6:36 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.