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 07-23-2007, 01:27 AM
Member
 
Join Date: Jul 2007
Posts: 41
gabriel is on a distinguished road
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:
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); } }
In the client I do that:
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();
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-06-2007, 04:39 AM
Member
 
Join Date: Jul 2007
Posts: 41
katie is on a distinguished road
check it out

Lesson: All About Sockets (The Java™ Tutorials > Custom Networking)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-11-2008, 02:55 PM
Member
 
Join Date: Jan 2008
Posts: 1
michaelmarosi is on a distinguished road
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!!!!
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-12-2008, 09:10 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-12-2008 at 09:24 AM.
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
An echo server using UDP sockets Java Tip java.net 0 04-07-2008 09:09 PM
Sending Mail Using Sockets Java Tip java.net 0 04-07-2008 09:05 PM
how to send .jar files client to server gobinathm Networking 1 12-25-2007 05:05 AM
Help with Sockets Eric Networking 3 12-01-2007 09:09 PM
send files through socket bbq Advanced Java 1 06-05-2007 03:08 AM


All times are GMT +3. The time now is 10:29 AM.


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