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

  • Home
  • SEARCH
  • 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 6946695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:35:54+00:00 2026-05-27T13:35:54+00:00

I have a client / server application made with C#. Its working fine when

  • 0

I have a client / server application made with C#. Its working fine when i send Strings of messages to the server. But i need to send (simple) objects to the server instead of Strings. But i’m not sure how to do this. I currently have this for my client:

The class i want to send:

[Serializable]
public class Actions
{
// Movement
public bool forward = false;
public bool left = false;
public bool backward = false;
public bool right = false;
}

Then i send the object using the default Send() command. But before that happends i convert the Actions class to a byte array first like so:

public void SendObject ( object obj )
{
    this.socket.Send ( this.ObjectToByteArray ( obj ) );
}

// Convert an object to a byte array
private byte[] ObjectToByteArray(object obj)
{
    if(obj == null)
        return null;

    BinaryFormatter bf = new BinaryFormatter();
    MemoryStream ms = new MemoryStream();
    bf.Serialize(ms, obj);
    return ms.ToArray();
}

On the server side i receive the data like this (and thats were i’m stuck at…):

public void OnDataReceived(IAsyncResult asyn)
{
    SocketPacket socketData = (SocketPacket)asyn.AsyncState;
    try
    {
        // Complete the BeginReceive() asynchronous call by EndReceive() method
        // which will return the number of characters written to the stream 
        // by the client
        int iRx  = socketData.m_currentSocket.EndReceive (asyn);
        char[] chars = new char[iRx +  1];

        // CONVERT THE BYTE ARRAY BACK TO AN OBJECT
        //object Cls = this.ByteArrayToObject ( socketData.dataBuffer );
    }
    catch ( ... ) { }
}

What do i have to do so i can access the object on the server?? Obviously when i do:
Cls.forward;

Then it gives me an error because it doesn’t know what properties the object has. Anyone any idea how to do 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-05-27T13:35:54+00:00Added an answer on May 27, 2026 at 1:35 pm

    Cast it from an object into a Actions:

    object Cls = this.ByteArrayToObject ( socketData.dataBuffer );
    Actions action = (Actions)Cls;
    

    That’s the simplest way to do it. You should also add exception handling, type checking, etc.

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

Sidebar

Related Questions

I have a client/server application that communicates with .Net remoting. I need my clients
I have a client server application in which the server and the client need
I have a client server application in which I need to transmit a user
We have a client/server application with a rich client front end (in .Net) and
I have a client server application that sends XML over TCP/IP from client to
I have a client-server application that uses .net remoting. The clients are in a
I have a client/server application. One of the clients is a CLI. The CLI
I have a client-server application written in Java using CORBA for the communication. The
I have a Client/Server application, where the Client and Server have some common tables
I have a client - server application, where I want to add a exception

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.