Sending mp3 files over QTcpSocket
I am trying write a server application which reads an mp3 file on the file system & sends it to a client app through QTcpSocket using the following code -
Code:
QFile htmlfile
("c:\\server_files\\ywr.mp3");
return;
//os.setAutoDetectUnicode(true);
os << "HTTP/1.0 200 Ok\r\n"
"Content-Type: audio/mpeg; charset=\"utf-8\"\r\n"
"\r\n";
os.flush();
// Streaming the file
clientSocket->write(block);
The server application crashes when this code is executed. What is the problem in the above code ? Is the method of reading the mp3 file faulty ?
Re: Sending mp3 files over QTcpSocket
It seeems you misunderstand the mime format.
Re: Sending mp3 files over QTcpSocket
I could not get the reason why u told that ? Can u explain a bit more ?
Re: Sending mp3 files over QTcpSocket
What is the end client you suppose will be reading your mp3 file ??
I dont think streaming means simply writing the file on socket. Thats file transfer, not streaming.
Re: Sending mp3 files over QTcpSocket
Quote:
Originally Posted by
ada10
The server application crashes when this code is executed. What is the problem in the above code ?
You need to post the complete code to know where and why it crashes. Your code snippet contains variables that are defined and created outside your snippet.
Another problem is that mp3's are binary. Are you sure that the way you send the data is correct? You can't send binary data as text for the simple reason that most, if not all, clients will parse text as text. So, if you have a \n or \t or \0 character in your binary, the client will corrupt the binary. Let alone the classes and functions you use to send the data which may corrupt the data already at your end.
Re: Sending mp3 files over QTcpSocket
Why are you trying to emulate a web server? Doing so requires much more work than what you used above. For example, you must parse the client request correctly before responding. Use a ethernet spy tool to see how a real web browser/server works.