4

I need to write a small java server that can be accessed through a web browser to download a file, preferably using sockets. Could anyone point me in the right direction as I can only find examples for the reverse (downloading from http using a java client).

Thanks,

Tom

calsign
  • 341
  • 3
  • 12

3 Answers3

2

Don't reinvent the wheel if you don't have to, embed Jetty to do this: http://wiki.eclipse.org/Jetty/Tutorial/Embedding_Jetty

jonathan.cone
  • 6,592
  • 2
  • 30
  • 30
  • That's sorta the heavy weight way to do it but I know from experience it works really well. :-) – djangofan Aug 28 '12 at 00:04
  • Does this come in the standard java? It's for a computing course so unfortunately I can't use things that make it easier. I have used sockets throughout the rest of it, and I think that's what they want us to do. – user1594409 Aug 28 '12 at 06:43
1

Depending on your over all requirements (ie protocol restrictions), you could start be looking at

Much of what it will come down to is:

  • How much complexity you want to get into (time and energy)
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

You can also use 3rd party libraries for this such as JBoss Netty and Apache MINA or Apache HTTP Comp . Also, I don't know much about it, but the new JDK7 has some new NIO apis which might possibly do the job also.

Here is a sample HTTP Server written with Apache HC.

NOTE: I think the trendy way of doing this sort of thing is to use "Web Sockets" which you will find info about that in the links I provided.

djangofan
  • 28,471
  • 61
  • 196
  • 289