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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:46:49+00:00 2026-06-02T04:46:49+00:00

i code socket application using blocing socket and use multithreading..my problem is i want

  • 0

i code socket application using blocing socket and use multithreading..my problem is i want to receive two large packet..as we know tcp must be split large data into multiple packet..this the scenario:

  1. i send 6 mb text file and tcp split packet into 2 separate packet
  2. at the same time i send 26 mb video file and tcp also split packet into 2 separate packet
  3. at my application i recive first part of text file let say it 3 mb of 6 mb
  4. and then i receive first part of video let say it 13 mb of 26 mb..

the question is how i know that first packet of text file and first packet of video file is a different data and should handle in different way..(different buffer maybe??)

sorry for my bad english..

thanks in advance..

this some part of my code

ns = client.GetStream();

        while (isListen == true && client.Connected)
        {
                while (!ns.DataAvailable)
                {
                    try
                    {
                        Thread.Sleep(1);
                    }
                    catch (Exception ex)
                    {
                    }
                }


                data = new byte[client.ReceiveBufferSize];
                //client.Client.Receive(data);

                int indx = ns.Read(data, 0, data.Length);

                string message = Encoding.ASCII.GetString(data, 0, indx);

                if (message == GetEnumDescription(TypeData.Disconnect))
                {
                    isListen = false;
                    server.ClientKeluar = objClient;
                    if (ClientDisconnected != null)
                    {
                        ClientDisconnected(objClient);
                    }
                    thisThread.Abort();
                    Server.kumpulanThread.Remove(thisThread);
                    Server._serverConnections.Remove(this);
                    client.Close();
                }
                else if (message.Contains(GetEnumDescription(TypeData.GetFile)))
                {
                    //jalankan proses pengambilan data
                }
                else if (message.Contains(GetEnumDescription(TypeData.ByteLength)))
                {
                    string length = message.Substring(6, message.Length - 6);
                    int len = int.Parse(length);
                    expectedLength = client.ReceiveBufferSize = len;
                    data = new byte[len];
                }
                else if (message.Contains(GetEnumDescription(TypeData.Image)))
                {
                    typeData = "Image";
                    dat1 = new byte[client.ReceiveBufferSize];
                    index = 0;

                }
                else if (message.Contains(GetEnumDescription(TypeData.Video)))
                {
                    typeData = "Video";
                    dat2 = new byte[client.ReceiveBufferSize];
                    index = 0;
                }
                else
                {
                    if (typeData == "Image")
                    {
                        expectedLength = expectedLength - message.Length;
                        if (expectedLength == 0)
                        {
                            Array.Copy(data, 0, dat1, index, message.Length);
                            if (ImageDelivered != null)
                            {
                                ImageDelivered(dat1);
                            }
                        }
                        else
                        {
                            Array.Copy(data, 0, dat1, index, message.Length);
                            index = message.Length;
                        }
                    }
                    else if (typeData == "Video")
                    {
                        expectedLength = expectedLength - message.Length;
                        if (expectedLength == 0)
                        {
                            Array.Copy(data, 0, dat2, index, message.Length);
                            if (VideoDelivered != null)
                            {
                                VideoDelivered(dat2);
                            }
                        }
                        else
                        {
                            Array.Copy(data, 0, dat2, index, message.Length);
                            index = message.Length;
                        }
                    }
                    else
                    {
                        expectedLength = expectedLength - message.Length;
                        if (expectedLength == 0)
                        {
                            dataToWrite = dataToWrite + message;
                            string text = dataToWrite;
                            if (MessageDelivered != null)
                            {
                                MessageDelivered(text);
                            }
                            dataToWrite = "";
                        }
                        else
                        {
                            dataToWrite += message;
                        }
                    }
                }
        }

may anyone give sample code so i can get inspiration to solve this problem?

  • 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-02T04:46:51+00:00Added an answer on June 2, 2026 at 4:46 am

    TCP protocol take cares of making segments of files and later joining them. You will get complete data in receive.

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

Sidebar

Related Questions

my application sends file to server using (socket tcp c#) the file transfer works
I have an java application using Socket TCP/IP and GUI. Server always listens connection
I have got a Client/Server Application that using Asynchronous Socket.My problem is i cant
I have a VC++2008 Form Application with some unmanaged socket communication code. I want
In the following code: tcp::socket socket(io_service); tcp::endpoint ep(boost::asio::ip::address::from_string(addr), i); socket.async_connect(ep, &connect_handler); socket.close(); is it
I am trying to use the code from Microsoft for an Async Socket connection.
I am using socket programming in vb.net to create a server client remoting application.
I currently work on a multithreaded application where I receive data using the following
I'm using Eclipse for an android application. I'm starting two emulators and sending a
I have try to make chat application with socket programing and I am using

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.