Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-04-2007, 05:11 PM
Member
 
Join Date: Aug 2007
Posts: 2
Nite is on a distinguished road
Problems sending file throught TCP sockets
I would like to transfer a file throught a tcp socket, here there is what the sender program does :

Code:
try{ File localFile = new File("shared/"+fileName); DataOutputStream oos = new DataOutputStream(socket.getOutputStream()); DataInputStream fis = new DataInputStream(new FileInputStream(localFile)); while(fis.available() > 0){ oos.writeByte(fis.readByte()); } } catch(Exception e){} }
and here what the receiver program does:

Code:
try{ File downloadFile = new File("incoming/"+fileName); downloadFile.createNewFile(); ois = new DataInputStream(connectionSocket.getInputStream()); fos = new DataOutputStream(new FileOutputStream(downloadFile)); while(ois.available() > 0){ fos.writeByte(ois.readByte()); } } catch(Exception e){} }

Where i m wrong? it doesnt work , it just create the new file in the incoming folder, but its size remains 0 byte

help a newbye please

Last edited by levent : 08-04-2007 at 06:44 PM. Reason: Code placed inside [code] tag.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-04-2007, 06:47 PM
Senior Member
 
Join Date: Dec 2006
Posts: 748
levent is on a distinguished road
You can try putting some System.out.println to test if the program enters your loops!

Also make sure that the socket connection is working. In these code segments, i did not see any mistakes. I think you should try to find the error by checking which steps are performed as expected and which are not. You can find the error in that way..
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-04-2007, 10:01 PM
Member
 
Join Date: Aug 2007
Posts: 2
Nite is on a distinguished road
the program didnt enter into the while loops, that was because of the available method, probably the two process didnt sync... anyway i solved in this way :

int length;
byte[] buffer = new byte[4096];
while((length = fis.read(buffer)) != -1){

out.write(buffer, 0, length);
}

and now it works, thanks anyway
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending Mail Using Sockets Java Tip java.net 0 04-07-2008 09:05 PM
Problems with file dir willemjav Java Applets 0 02-07-2008 01:08 AM
Servlet sending the file (setting header) Java Tip Java Tips 0 01-27-2008 09:14 PM
sending image file from JSP to Servlet ravian Advanced Java 2 01-10-2008 03:34 PM
problems with the name of file bbq Java Servlet 0 06-28-2007 05:47 AM


All times are GMT +3. The time now is 02:47 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org