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 06-05-2007, 02:41 AM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
send files through socket
Well I tried in a lot of ways to do that, but not always works.

If you have any idea about that and you have the secure and efective way to send files through socket I'll appreciate that.
This the code that I am using, it works well for the small files, but for the big ones don't work

Client
Code:
synchronized (Writing) { try{ FileInputStream f=new FileInputStream(up); byte bytesFile[]=new byte[f.available()]; f.read(bytesFile); f.close(); Writing.writeUTF(up.getName()); Writing.flush(); Writing.write(bytesFile); Writing.flush();
Server
Code:
File dir=new File(Command.substring(5)); File n=new File(dir,reading.readUTF()); FileOutputStream nn=new FileOutputStream(n); do{ byte bytesFile[]=new byte[reading.available()]; nn.write(bytesFile); nn.flush(); }while(reading.available()!=0); nn.close();
Any suggestions?

Last edited by bbq : 07-04-2007 at 08:47 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-05-2007, 03:08 AM
Senior Member
 
Join Date: Jun 2007
Posts: 164
Heather is on a distinguished road
The sockets can be slows, depends on your connection.
The best is that you send an integer indicating how many bytes are you going to send. In other side, reads the integer, and then the number of bytes that indicates.

Another choice is that the sender closes the connection, in this way the receiver reading until the connection close.

good luck
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
how to send files through sockets gabriel Advanced Java 3 01-12-2008 09:10 AM
how to send .jar files client to server gobinathm Networking 1 12-25-2007 05:05 AM
Server socket - send image to client Hinty Networking 0 11-30-2007 09:15 PM
Socket programming - accepting files ravian Networking 2 11-29-2007 11:40 AM
XML through a socket Heather XML 2 07-04-2007 10:31 AM


All times are GMT +3. The time now is 01:07 AM.


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