• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Transferring files over the network: is this possible?

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I've been asked to write a program with the following specs:
-The server uploads a file to a specified client.
-Save in a database how long it took for the file to get there.
-Get the file back from the client
-Save in the database how long it took for the file to go from client to server
-Repeat the operation every 30 minutes for the next few months.
I've never used sockets before, and I'm not sure if the above is possible. Is it?
If so, which steps should I take in order to write that program?
Thanks,
Marie
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it's possible. There is a good Sockets tutorial in one of the threads around here. Somebody will give us a link Real Soon Now.
As for basics, you'll need a client program and a server program. The server program will start first and open a ServerSocket on a port. The client will open a regular Socket connecting to the server machine's address and the same port. When a client connects, the ServerSocket on the server gives out a new Socket for communication with the client. If you have multiple clients - usually something you have to allow for - look into the server program starting a new thread each time a client connection happens.
Once you're connected, both ends get the input and output streams from their respective sockets. To send a file, the client writes file bytes and the server reads them and writes them to disk. To receive a file, the the server reads file bytes from disk and writes them back to the client. Think about a few bytes sent from client to server to identify the scenario, like "I'm about to send file xxx" or "please send me file zzz".
I hope that gives you enough to start fiddling with. As you get bits of this running (or not) please post code snippets & questions!
 
Marie Mazerolle
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply, Stan!
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic