Results 1 to 4 of 4
- 07-23-2007, 12:27 AM #1
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
how to send files through sockets
I'm developing a program and I need to send files through sockets
I'm using BufferInputStream,DataInputStream.
I choose some file from server and then send it to the client.
The client receives it but it doesn't open!
I send you my code
In server I do something like that:
In the client I do that:Java Code:public class Server { static final int Port=5000; public int nClients=0; private String file="./files/3.jpg"; /** Creates a new instance of server*/ public Server() { try { ServerSocket serverSock=new ServerSocket(Port); System.out.println( Port); while(true) { serverSock.accept(); Socket cliente=serverSock.accept(); nClients++; System.out.println(nClients); SClient(client,nClients); SocketThread thread=new SocketThread (client,file,nClients-1); hilo.start(); } } catch(Exception ex) { System.out.println(ex); } }
Java Code:DataInputStream en = new DataInputStream (skClient.getInputStream()); byte buffer[] = new byte[breaden]; //breaden=en.read(buffer); File rec=new File("./rec/1.jpg"); rec.setReadable(true); rec.setWritable(true); //FileOutputStream f=new FileOutputStream(rec); FileOutputStream f=new FileOutputStream ("./rec/1.jpg"); f.write(buffer); skClient.close();
- 08-06-2007, 03:39 AM #2
Member
- Join Date
- Jul 2007
- Posts
- 41
- Rep Power
- 0
- 01-11-2008, 01:55 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 1
- Rep Power
- 0
Sending files through sockets
Anyone know where I can access a complete tutorial on how to send files through java sockets? If so, please tell me where, I'd be glad to receive any references. Thanks in advance!!!!:)
- 01-12-2008, 08:10 AM #4
Gabriel, try to review this and see where you're going astray. This is something I plan to implement in my custom chat client, when I someday get to it, due to time constraints.
Best of luck!
EDIT: See these tutorials found here in our very own community, at the end - which makes note of using ObjectOutputStream and ObjectInputStream.Last edited by CaptainMorgan; 01-12-2008 at 08:24 AM.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
Similar Threads
-
An echo server using UDP sockets
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:09 PM -
Sending Mail Using Sockets
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:05 PM -
how to send .jar files client to server
By gobinathm in forum NetworkingReplies: 1Last Post: 12-25-2007, 04:05 AM -
Help with Sockets
By Eric in forum NetworkingReplies: 3Last Post: 12-01-2007, 08:09 PM -
send files through socket
By bbq in forum Advanced JavaReplies: 1Last Post: 06-05-2007, 02:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks