Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

trondb

Sending a binary file from server to clients

This topic is 5729 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a client server program, that I am trying to extent to a Radio broadcast program... How do I send a binary file (WAV in my case) from the server to the client?!?!? For starters I just want to read the file from disk on the server side, send it over to the client, and write it to disk there... Thanks alot, I really need help on this one! "That''s Tron. He fights for the users."

Share this post


Link to post
Share on other sites
Advertisement
I don''t know how you do all the transfers, but I myself would define a maximum packet size, take a special leading character and then read 128 chars for file, add leading char infront of it and then send to the other side. Take a look at the SMTP protocol, how they solved it in there. Because there is an difference between commands and attachments.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites
Tron,

I can answer this question a bit later. I''m at work right now, so I dont have a chance to verify anything.

Basically though, it looks like this:

Server:
Initialize app
Load Wave files
Start network module
On receipt of a client, send file to client

Client:
Initialize app
Connect to server
Wait for file
Play file

The send and receive is, I believe, what you''re having problems with?

One way to do it would be to construct a header, which details information about the sound file being sent, ie, size in bytes, etc...

After you construct the header, send it followed by the file over TCP/IP to the client.

The client can then read the known header format, obtain the file information, and then read the appropriate size buffer off of the socket.

I''m writing my own example of this to test the theory...when I finish I will post a link to the code.

Best Regards,

Jeromy Walsh
Programmer
Liquid Entertainment
------------------------
"The question isn''t how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" -Boondock Saints

Share this post


Link to post
Share on other sites
Awesome JWALSH!!!
That''s pretty much what I need, Im sure. I want the audio to be streaming, so that clients can log on in the middle of the broadcast, and start playback at any time... So I definitely should do that header stuff you talk about!

Right now I am confused about how the read and write the file, there are so many different ways to do that, and I''m not sure which method is the best for this kind of traffic.

Let me know as soon as you got your stuff posted,
thanks a bunch again!!!

"That''s Tron. He fights for the users."

Share this post


Link to post
Share on other sites
Tron,

I''ll have to do a bit of research in order to make it streaming.

Best Regards,

Jeromy Walsh
Programmer
Liquid Entertainment
------------------------
"The question isn''t how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" -Boondock Saints

Share this post


Link to post
Share on other sites
Hey Tron,

After doing some research, it looks like it''s pretty difficult to stream .wav files. The reason being is that the ratio of file size to play time is very high.

The way streaming is done is the data is broken up into small chunks and then sent over the net in segments. The individual segments are then added to the end of the song on the receiving end and the song continues to play.

One of the ways in which this is done is through buffering. A certain % of the file is sent first, this is supposed to guarentee enough time to continue downloading without interrupting play. Then the new stuff that you downloaded, is used as the buffer to download even more data...and on and on.

Well, the problem with .wav files is that a 400KB file is roughly 4 seconds in length. If you divide the file size by the play time, you see that a single second of a wave file is about 100 KB. Most dial-up modem users get data at about 5 KB per second. Which means that on a dial up modem, it would take about 20 seconds, just to download the first 1 second of the song. As you can probably tell, buffering under those conditions is impossible without data compression.

Once you realize that compression or something else is required, you also realize that it might be best just to consider using another well established file format that already has loaders, creation tools, etc... such as MP3.

In the mean time, I did find out some things. If you''re using Windows, you can just use the MFC class CSocket to initialize streaming data transfer across the net. Then you can use DirectSound''s streaming playback capabilities to add the segments received over the net to the end of the song.

So you''ve got a way to send data, and a way to stream it into a play device. So the only thing you''re missing is a file format to use and a way to load it into a format that DirectSound can use to synthesize it.

Hope that helps.

If/when I get/write a loader for MP3 and finish the project, I''ll post it. But in the mean, I''d consider doing more research yourself.

Best Regards,

Jeromy Walsh
Programmer
Liquid Entertainment
------------------------
"The question isn''t how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" -Boondock Saints

Share this post


Link to post
Share on other sites
thanks again, J!
I am still sticking to wave and will probably extend it to use MP3 later on. And I am using DirectAudio to playback streaming files, so that should be no prob... I am still having problems with simply transferring the file though...

Its kinda weird because I am reading the file into a char* buffer at the server side, splitting it into chunks and transferring one at the time. Just to check, I also save those chunks to a file as I send them out on the socket. That file works just fine, but the file stored at the client side is corrupt... opening it up in a textviewer it looks pretty much the same, but is missing a symbols here and there...

The weird thing is that I am using exactly the same datatypes and sizes for the buffers, fileformats and so on on both sides, so I have no Idea what causes the data to go bad during the process... any ideas? I have the sourcecode at my site in case you have an idea what I am doing wrong:

http://groups.msn.com/californiacornboy/Documents/Files/StreamCasterInternetRadio.zip

Thanks again for all your time, you have been a great help!

"That''s Tron. He fights for the users."

Share this post


Link to post
Share on other sites
Tron,

Without looking at your code I''d say, perhaps the data isnt really being corrupted as much as "reversed" or formatted. When you write to a file you can write in either formatted or unformatted mode. Make sure you''re using "unformatted". Also, when you write to a file you can write in either Big-Endian or Little-Endian, which determines in which order the bytes are written to the file. If you are then reading the file in another mode, I''m not sure what the default is, then you''ll find that you get different values.

Also, why are you writing to a file before sending?

To check the data, open up the files in a hex-editor, and focus on the numbers, not the symbols. See if the numbers are reversed or something like that.

Lastly, stick with wave files if you want, but without compression, you will never be able to stream wave files. You can send them completely over and play them, but you''ll never be able to play them as you copy them over. At least not on a 56Kb modem.

You might be able to stream wave files on ADSL or some other broadband connection.

Best Regards,

Jeromy Walsh
Programmer
Liquid Entertainment
------------------------
"The question isn''t how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" -Boondock Saints

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!