File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File transfer through Socket

 
Guy Geelen
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm implementing a client-server application in Java. I want to store all my shared files on a server and the application itself (which makes use of thes files) on different workstations.

How can I send these files from the server to the workstation through LAN and vice versa?

Can anyone give me some code or explain what steps I have to take?

Thanks
Guy
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious about what your server is. What protocols does your client use to talk to the server otherwise?

If you're writing the server, you can do file transfers via sockets for sure. Make up a little protocol where the client sends a request like "GET name" and the server maybe returns "SIZE 9999\n raw bits ".

If the server can do HTTP, or if you could install a separate HTTP server, you could use URL and HTTPUrlConnection in the client.

And if the server can do FTP you could Google for a good Java/FTP package.

Any of that sound useful?
 
Guy Geelen
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No that's not what I'm looking for.
My server is a Linux (Slackware) server where in the first place a db4o database is running on port 4488. In the application I use some files, like RTF and xml files. When I store those files on each client PC, all changes are only local. That's why I want to store them on the server...
So I just need to know how I transfer those file on the server to the local PC's (clients)

I'm thinking of the following: create a socket on the server with eg. port 3400 and then the client makes connection on that port for transferring the file. But I'm not quite sure if this is going to worl, or where exactly I need to start...

Guy
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far, it still sounds to me like Stan's answer gives you a couple good options. I'm not seeing why that's not what you need. Your idea about opening a socket on the server is what Stan talks about in his second paragraph. Is there more than one file that a client might need? Then you need some way for the client to communicate what file it's looking for. If the client says "GET <filename>" to the server socket, followed by a return, that's one simple way to do it. If you need wider functionality like the ability to browse directories or send files as well as receive them, then it may well be easier to just use an existing Java/FTP package.

If this is your first experience with sockets in Java, a good starting point may be the Java Tutorial.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic