Cannot transfer a wave-file over a socket?!?

Started by
17 comments, last by trondb 21 years, 4 months ago
I cannot get this to work. I am simply trying to transfer a wave file over a client/server connection using winsock! 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 few 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."
"That's Tron. He fights for the users."
Advertisement
Can''t download that unless you have an MSN Passport. I have one but it doesn''t work with my browser of choice. Can I suggest you find some other storage space, or perhaps post some code here? I can''t imagine your sending and receiving code would be too long.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Does the ''anomaly'' happen at certain intervals? Do they corespond with the lenght of the chunks you split the file?
i cant see a pattern no, I have cleaned up my code, and it seems that it works for smaller files, but when they get larger, data gets corrupted, and chunks are lost even over TCP! I tried slowing down the sending, but that didnt help either...

"That''s Tron. He fights for the users."
"That's Tron. He fights for the users."
So you save it to a file at the receiving end... is that file the same size as the file that you sent?

Are you checking how many bytes send() and recv() actually did send? You may have told them to send/recv say 8192 bytes or whatever but that doesn''t mean they actually did.

I suggest you try sending a text file first. Fill this text file with text that will immediately be obvious if it wasn''t received properly, ie. something like:

ABCDEFGHIJKLMNOPQRSTUVWXYZ012345679
ABCDEFGHIJKLMNOPQRSTUVWXYZ012345679
ABCDEFGHIJKLMNOPQRSTUVWXYZ012345679
ABCDEFGHIJKLMNOPQRSTUVWXYZ012345679
ABCDEFGHIJKLMNOPQRSTUVWXYZ012345679
....

Viewing the received version of this will give you a much clearer idea of what''s going on than looking at raw wav data
(You might need to make the text file very large to have a better chance of bringing up the same errors you had with the wav file.)
Yeah thats a good idea! Thanks...
Well, it appears that there is no garble actually - but once I start sending files over a certain size, packets are lost. Files of size up to 90Kb work, but more than that no...

I send chunks of 128 bytes at a time, and count how many of these the client receive. The server might send something like 135 chunks, while the client only counts 134. For even bigger files, more chunks are lost. The number of lost chunks is consistent for every run of the program with the same file, though.... I also tried to change buffersize. Running with chunksize 8, I sent 21387 chunks but received only 21319. Thats 68 lost chunks * 8 = 544bytes that TCP lost? That is a lot for a guaranteed-delivery service like TCP isnt it? I have also tried to slow down my program in order to give the CPU, HD and network more time to see if that helped avoiding the errors, but it didnt help.



"That''s Tron. He fights for the users."
"That's Tron. He fights for the users."
It is most likely a problem with your code. TCP/IP doesn''t lose packets.

Try posting some of your send/recv code.
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Nevermind, I missed your link to the code. I''ll take a look at it.
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
Awesome, I really appreciate it! I know how demanding it can be to go through someone else''s code.

This problem is so confusing and frustrating to me, and I''ve worked my ass off trying to find the source of the instability.

"That''s Tron. He fights for the users."
"That's Tron. He fights for the users."
Like Kylotan suggested, try to post the code here, it can''t be that big...

Height Map Editor

This topic is closed to new replies.

Advertisement