LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2007, 12:59 PM   #1
manolakis
Member
 
Registered: Nov 2006
Distribution: xubuntu
Posts: 464

Rep: Reputation: 37
Sockets in Java


Hi there
I was wondering how is it possible for a Server to send a folder with lets say text files to a Client. How can we copy a folder and its contents and sending it as bytes to a client.

Thanks
 
Old 10-01-2007, 12:17 PM   #2
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
Assuming that you know how to send files over the sockets, sending a folder should be almost similar to sending files.

As I see it, a folder is just a container to hold files and the *real* data lies in the files which it contains. So there are two things which you need to do:

1) Recursively traverse the contents of the folder and send the files.
2) Figure out a mechanism where the sender can somehow communicate the folder hierarchy to the receiver, so that it can create the same hierarchy at its end.

hope this helps.
 
Old 10-02-2007, 06:40 AM   #3
Nick_Battle
Member
 
Registered: Dec 2006
Location: Bracknell, UK
Distribution: SUSE 13.1
Posts: 159

Rep: Reputation: 33
A thought: it might be easiest to gzip up the directory structure you want at the sender, and unpack it at the receiver. Java has ZIP helper classes (look in java.util.zip). It solves the problem of how to communicate the directory hierarchy, though you still have to traverse the tree of files to create the archive, unless you cheat and run a gzip command outside your Java program. :-)

HTH,
-nick
 
Old 10-03-2007, 02:01 AM   #4
devn
Member
 
Registered: Mar 2007
Location: Bangladesh
Distribution: Suse, Solaris
Posts: 40

Rep: Reputation: 15
Quote:
Originally Posted by Nick_Battle View Post
A thought: it might be easiest to gzip up the directory structure you want at the sender, and unpack it at the receiver. Java has ZIP helper classes (look in java.util.zip). It solves the problem of how to communicate the directory hierarchy, though you still have to traverse the tree of files to create the archive, unless you cheat and run a gzip command outside your Java program. :-)

HTH,
-nick
This is a good idea to use the java.util.zip class for zipping the folder. However, depending on System to get the gzip tool to actually zipping the directory may not be suitable (a user may not have gzip tool installed, i.e. it doesn't come with all OS, specifically win32 versions).
You could also use jar utility of java to jar the contents (since its natively installed once you have jre installed in your system). Its almost as tar, with j prefix.

I guess you should now have enough options to choose from.
Happy java-(ing)!!!
 
Old 10-03-2007, 05:09 AM   #5
Nimoy
Member
 
Registered: Jun 2003
Location: Currently Denmark
Distribution: Ubuntu 15.04
Posts: 336

Rep: Reputation: 30
A great book on JAVA network programming and ressources..

An Introduction to Network Programming with Java

Jan Graba

ISBN 0 321 11614 3

Is actually a very good read - The site below also has the java examples from the book. [EDIT: They have password locked the resources - Didn't use to be that way as far as I remember]



http://www.booksites.net/download/graba/download.htm

Last edited by Nimoy; 10-03-2007 at 05:13 AM. Reason: Notice: Resorces pwd locked
 
Old 10-03-2007, 08:13 PM   #6
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
Quote:
Originally Posted by devn View Post
This is a good idea to use the java.util.zip class for zipping the folder. However, depending on System to get the gzip tool to actually zipping the directory may not be suitable (a user may not have gzip tool installed, i.e. it doesn't come with all OS, specifically win32 versions).
You could also use jar utility of java to jar the contents (since its natively installed once you have jre installed in your system). Its almost as tar, with j prefix.

I guess you should now have enough options to choose from.
Happy java-(ing)!!!

I also like the idea of compressing the folder and then sending it as one file over the network. I dont see compression as an overhead here because the data needs to be send over the network, where sending raw uncompressed data can be *far* more costly than locally compressing the data.
 
Old 10-03-2007, 11:34 PM   #7
devn
Member
 
Registered: Mar 2007
Location: Bangladesh
Distribution: Suse, Solaris
Posts: 40

Rep: Reputation: 15
Quote:
I also like the idea of compressing the folder and then sending it as one file over the network. I dont see compression as an overhead here because the data needs to be send over the network, where sending raw uncompressed data can be *far* more costly than locally compressing the data.
Is it possible for you to later share the class you will code to compress and transfer the data? I was working on something like this few months back on C#. Didn't finish it though.
 
Old 10-09-2007, 09:52 AM   #8
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
Quote:
Originally Posted by devn View Post
Is it possible for you to later share the class you will code to compress and transfer the data? I was working on something like this few months back on C#. Didn't finish it though.
Although manolakis is actually trying to do this, but if I get the chance I may try it out.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Sockets: Help with a simple chat client/server Mega Man X Programming 6 07-15-2009 05:16 PM
Program to forward tcp sockets to unix domain sockets mikepol Linux - Networking 0 09-27-2007 09:49 AM
Problem with Java sockets dickgregory Programming 3 03-28-2006 07:46 AM
Java - sockets ok in Linux, not Win? rylan76 Programming 6 09-05-2005 01:33 AM
Java cannot create sockets in redhat fc4. ramman Linux - Networking 8 07-26-2005 10:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration