Results 1 to 2 of 2
Thread: send files through socket
- 06-05-2007, 01:41 AM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 132
- Rep Power
- 0
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
ServerJava 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();
Any suggestions?Java 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();Last edited by bbq; 07-04-2007 at 07:47 AM.
- 06-05-2007, 02:08 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 164
- Rep Power
- 6
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
Similar Threads
-
Server socket - send image to client
By Hinty in forum NetworkingReplies: 2Last Post: 03-14-2009, 07:39 AM -
how to send files through sockets
By gabriel in forum Advanced JavaReplies: 3Last Post: 01-12-2008, 08:10 AM -
how to send .jar files client to server
By gobinathm in forum NetworkingReplies: 1Last Post: 12-25-2007, 04:05 AM -
Socket programming - accepting files
By ravian in forum NetworkingReplies: 2Last Post: 11-29-2007, 10:40 AM -
XML through a socket
By Heather in forum XMLReplies: 2Last Post: 07-04-2007, 09:31 AM


LinkBack URL
About LinkBacks

Bookmarks