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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:13:42+00:00 2026-06-13T01:13:42+00:00

I have async Server and async Client on .net Sockets. Client creates object(for example

  • 0

I have async Server and async Client on .net Sockets.
Client creates object(for example class UserInfo), serializes him, and writes in byte[].
Also Client has some file(1.png for example).
Client need to sent serialized UserInfo and 1.png to the server.

I use for file,

Socket.BeginSendFile Method (String, AsyncCallback, Object)

and for byte[] object

client.BeginSend(byteData, 0, byteData.Length, 0,
new AsyncCallback(SendCallback), client);

Server must receive this date together and understand what is file and what is serizalize object(because server has only one method for receive data).

listener.BeginAccept(
new AsyncCallback(AcceptCallback),
listener);
...
AcceptCallback(IAsyncResult ar)
{...
 handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                new AsyncCallback(ReadCallback), state);
}

and our logic in

ReadCallback(IAsyncResult ar)
    {...}

How to receive this data correctly? In finally i need that server has 1.png and UserInfo object.(and distinguish them). Moreover, because the server is asynchronous, it should not be confused when receiving data from multiple clients simultaneously

i have one idea, but i think this is wrong:
Try to use on a client

Socket.BeginSendFile Method (String, Byte[], Byte[], TransmitFileOptions, AsyncCallback, Object)

with byte[] preBuffer, where i will write header, such this “…”
and on server i try to find this header, cut it, analyse and do some activity.

Is there a way easier and more correct?

Thanks.

  • 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-13T01:13:43+00:00Added an answer on June 13, 2026 at 1:13 am

    Each channel (socket) should have definite and known protocol, in terms of implementation – well known type of objects. So introduce a main class which will encapsulate all data which could be sent via this socket:

    public interface IPacketWrapper
    {
       IEnumerable<byte> Payload { get; }
       UserInfo UserDetails { get; }
    }
    

    So client and server exchange by objects which implements IPacketWrapper so you can put together both binary data and UserInfo, then serialize/deserialize this object on client/server side respectively.

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

Sidebar

Related Questions

I have written an async UDP client to talk to a server at my
Hi I have TCP/IP client server application. i want to send large serialized object
Helloes good people of Stack Overflow, I have a .NET client-server application running with
So just recently, my async server code which relies on pthread_mutex_timedlock seem to have
I have two async classes in my application which you can see below class
I have this sample code for async operations (copied from the interwebs) public class
I have a receive callback from an async client method that is supposed to
I have a very simple server/client performance test using boost::asio on Windows and it
I have developed a TCP server by async pattern under .net4 in c# that
I have a ASP.Net web app with jquery implemented on the client side. within

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.