permaculture playing cards
The moose likes Sockets and Internet Protocols and the fly likes Data loss during file transfer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Data loss during file transfer" Watch "Data loss during file transfer" New topic

Data loss during file transfer

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

I am loosing data when I send it to my client. How do I figure this? When I receive the data (music) and play it, it sounds off. Some sounds don't play correctly and sound like they are missing some data. While the general music audio lines are still hearable, it just sounds like the quality is off. When I play the songs without the transfer, they sound fine. I am guessing there is something wrong with the way I do the transfer. Small amounts of bits are being "chewed off" (sorry, I couldn't resist) and you can hear it. Please note that I tried this on my computer and on another computer through my network. They sounded the same, so it isn't my internet connection. I also tried it with "localhost". It was the same quality, poor.

John Price

EDIT : Please try this code yourself. It runs 100% fine. Just put the server in a folder, along with a file named "SongList.txt". You will need a WAV, AU, or other supported file type audio files in the server folder. "SongList.txt" should contain a list of those audio files. Here is a sample of what is in "SongList.txt" :

Server :

Client :

“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

You cannot receive binary data as a String using a Reader of any kind and then convert it to bytes without some data loss. Readers interpret the data they read, making various substitutions. You must instead use an InputStream to read the raw bytes directly.

[Jess in Action][AskingGoodQuestions]
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You aren't closing your resources properly. This might cause "weird" behaviour. Also there are some places in your code where you should use generics.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Sorry, I guess this is a little old. Haven't worked on the project for awhile, but the "parsing to from string" isn't an issue anymore as I fixed it awhile ago (in more recent posts).

Closing the topic,
John Price
I agree. Here's the link:
subject: Data loss during file transfer
jQuery in Action, 3rd edition