私はこの問題に数日間取り組んでいますが、問題が何であるかを理解できません。iOSからC#ベースのサーバーにソケットを介してサウンドファイルを送信しようとしています。コードは次のとおりです。
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
データを読み込むためのC#側(コードを短縮しようとします)では、次のようになります。
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
私が抱えている問題は、iPhoneに記録された.cafファイルを送信していることです。ただし、サーバーマシンで再生しようとすると、QuickTimeからファイルを再生できないと表示されます。また、バイト単位のファイルサイズは、元のファイルサイズよりもわずかに短い(約20kb短い)ようです。何か案は?たくさんのコードを投げてしまったことをお詫びします。どんな助けでも大歓迎です!
PS。接続は正しく開いており、データを逆に送信することは完全に機能します。