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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:45:51+00:00 2026-05-16T02:45:51+00:00

i am developing application which send and receive data between two computers but there

  • 0

i am developing application which send and receive data between two computers but there is problem which i am facing when i send data the file size would be 4.56 kb but when i receive data on other side the file size reduce to 1.42 kb and data write in file also in complete my receiving byte size is 1024 * 5000.i am using c#.i am using TCP

here is my code

i am first sending data to tell other computer what file i want to receive

 private void GetLoginFile()
    {
        Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        try
        {
            char[] delimiter = splitter.ToCharArray();
            byte[] fileName = Encoding.UTF8.GetBytes(myIP + "_GetLoginFile"); //file name
            byte[] fileData;
            fileData = Encoding.UTF8.GetBytes("null");
            //byte[] fileData = reads.ReadToEnd().to; //file
            byte[] fileNameLen = BitConverter.GetBytes(fileName.Length); //lenght of file name
            clientData = new byte[4 + fileName.Length + fileData.Length];

            fileNameLen.CopyTo(clientData, 0);
            fileName.CopyTo(clientData, 4);
            fileData.CopyTo(clientData, 4 + fileName.Length);
            System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse(serverIP);

            IPEndPoint ipEnd = new IPEndPoint(ipAdd, 9050);
            clientSock.Connect(ipEnd); //target machine's ip address and the port number
            clientSock.Send(clientData);

            byte[] clientData1 = new byte[1024 * 5000];
            string receivedPath = mypath + "XML\\";

            int receivedBytesLen = clientSock.Receive(clientData1);

            int fileNameLen1 = BitConverter.ToInt32(clientData1, 0);

            string fileName1 = Encoding.ASCII.GetString(clientData1, 4, fileNameLen1);
            //string file = Encoding.UTF8.GetString();

            BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + fileName1, FileMode.Append));
            bWrite.Write(clientData1, 4 + fileNameLen1, receivedBytesLen - 4 - fileNameLen1);
            //clientSock.Shutdown(SocketShutdown.Send);

            bWrite.Close();
            clientSock.Close();
        }
        catch (Exception ex)
        {
            clientSock.Close();
            MessageBox.Show(ex.Message);
        }
    }

can anyone help me out to solve this problem.

  • 1 1 Answer
  • 1 View
  • 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-16T02:45:52+00:00Added an answer on May 16, 2026 at 2:45 am

    Well, you haven’t given any code… but I suspect it’s your receiving code which is wrong.

    You should be looping round, reading until a Read call on the stream returns 0. Don’t assume you’ll get all the data in one call.

    EDIT: Yup, look at your receiving code:

    int receivedBytesLen = clientSock.Receive(clientData1);
    

    What makes you think you’ve received all the data you need in that one call? You need to loop round, receiving until either the other end closes the connection, or you’ve read all the data you need.

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

Sidebar

Related Questions

I am developing Windows Phone 7 application in which I send encrypted data to
I am developing application which is having Gujarati font in text-view but my problem
I am developing one GPS Application. Which will send the location data to server
I'm developing an application (user space) which send notifications of value changes via network.
I'm developing an application via which one can send sms by directing it to
I am developing a simple application which has to send an SMS message from
I`m developing an application which receives data from my GPS device like coordinates, speed
I'm developing an application in which users upload pictures to server and then send
I am developing an iPhone application which is completely based on web data. If
I'm developing a multi-user application which uses a (postgresql-)database to store its data. I

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.