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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:07:46+00:00 2026-06-14T10:07:46+00:00

I have been dealing with the issue for a few days now and I

  • 0

I have been dealing with the issue for a few days now and I cannot figure out what the issue is. I am trying to send a sound file over a socket from iOS to a C# based server. The code is as follows:

Objective C:

NSData * data = [NSData dataWithContentsOfFile:uri];

int length = 0;
int totalLen = [data length];
uint8_t buffer[1024];
Byte * readBytes = (uint8_t *)[data bytes];

//Tell the server what this is
int headerInt = 2;
NSData *header = [NSData dataWithBytes:&headerInt length:sizeof(int)];
[outputStream write:[header bytes] maxLength:sizeof(int)];
//Fill up the rest of the header (132 bytes total)
UTF8Char emptyHead[128];
[outputStream write:emptyHead maxLength:sizeof(char) * 128];

do
{
    int indexLen = (1024 > (totalLen - length) ? (totalLen- length) : 1024);
    memcpy(buffer, readBytes, indexLen);

    int written = [outputStream write: buffer maxLength: 1024];

    if (written < 0)
    {
        break;
    }

    length += written;


    readBytes += written;
}
while (length < [data length]);

[self sendENDS]; //Inform the server I am done

On the C# side for reading the data in (will try to shorten the code down), it is as follows:

        if (read > 0)
        {
            //Write this into an overall buffer
            obj.bufferStream.Write(obj.buffer, 0, read);
            obj.bufferStream.Flush();

            if (obj.buffer.Length > 4)
            {
                //Check if the client sent an "end of stream" flag
                byte[] checkBuff = obj.buffer.Skip(read - 4).Take(4).ToArray();
                string terminator = ASCIIEncoding.ASCII.GetString(checkBuff);
                if (terminator == "ENDS")
                {
                    obj.readMe = false;
                }
            }
            if (obj.readMe == true)
            {
                obj.buffer = new byte[ConnectionObject.bufferSize];//I keep forgetting to clear the buffer
                localSocket.BeginReceive(obj.buffer, 0, ConnectionObject.bufferSize, SocketFlags.None, new AsyncCallback(recieve), obj);
            }
        }
//...the rest takes care of taking the obj.streamBuffer and writing it into a file along with handling other types of requests

The issue that I have, is that I am sending over a .caf file recorded on the iPhone. However, when I try to play it back on the server machine, QuickTime tells me that the file cannot be played back. Also, the file size in bytes seems to be slightly shorter (about 20kb shorter) than the original. Any ideas? I apologize for throwing so much code up. Any help is greatly appreciated!

PS. The connection is open correctly and sending data the other way around works perfectly.

  • 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-14T10:07:48+00:00Added an answer on June 14, 2026 at 10:07 am

    As it turns out that while Davyd is very much correct, the actual issue was in the buffer sizes not properly set up. I had a blank in front of the bytes file which caused issues in reading it. Align your buffers/socket read right next time 🙂

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

Sidebar

Related Questions

I have been wracking my brain trying to figure out how to download a
For a period of time, I have been dealing with an issue in pagination
Have been trying to encrypt an xml file to a string so that I
This is an issue I have been dealing with for months, and I would
I've been dealing with this issue for awhile now ( https://stackoverflow.com/questions/12982012/unit-testing-core-data-to-many-relationship ), but I've
I have an issue that I have been dealing for way to long Please
I've been having trouble trying to implement this for a couple of days now.
I have been dealing with a problem for a while. How can I set
I have been dealing with Nasm and GNU C inline asm on a Linux
I've been dealing with a frustrating problem recently. I have a lot of reflection

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.