• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem in file transfer

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I had a problem in doing my mini-project last week and the problem is that when I am performing file transfer using TCP, the file on being received on the client side is having some dummy characters also along with the original file. I have tried a lot but could not eliminate those garbage characters......Please help me out with this and I will be very thankful to you people. I am attaching the code of both server and client in this post.

Server:


Client:


Please help me out with this.....Thank you.
[ October 09, 2008: Message edited by: Ulf Dittmer ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please UseCodeTags when posting code of any length. It's unnecessarily hard to read, and will deter many people from looking at it. I have added those for you, but please remember to do that from now on.

I haven't looked at the code in detail -there are so many streams and readers that it's hard to figure out what's being used for what- but I noticed a couple of things. First, never do something like "}catch(Exception e){}" in I/O code. How will you know that there are problems? At the least, print a message to the console.

Secondly, you will get extraneous characters through the "pw.println(str1); pw.println(str2); pw.println(str3); pw.println(str4);" statements. Those strings already have "\r\n" at the end, so if you use "println" -instead of "print"- there will be extra newlines and possible extra carriage returns.

Lastly, you may run into problems if client and server don't run on the same machine. That's because you're not specifically dealing with encoding in the "new String" and "String.getBytes" calls. Those will use the platform default encoding, which may differ on different machines.
[ October 09, 2008: Message edited by: Ulf Dittmer ]
 
Muddasani Rohit Reddy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf for your valuable suggestions.I am still an amateur at programming and these tips from you would definitely help me.I would try out the suggestions given by you , and thank you for taking the pains to go through my code.
 
Muddasani Rohit Reddy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Ulf for your valuable suggestions.I am still an amateur at programming and these tips from you would definitely help me.I would try out the suggestions given by you , and thank you for taking the pains to go through my code.
 
reply
    Bookmark Topic Watch Topic
  • New Topic