How to implement HttpDaemon - http-daemon

I am a Java Programmer.I have to implement HttpDaemon.I think it would be written in 'C' or 'Perl' . Kindly help me in what is it and How to implement it.

Read and understand all the relevant specs.
Code it up. Start with java.net.ServerSocket.
The first step is the hard one!
Seriously, there are many industrial-strength web servers written in Java: Tomcat, Jigsaw, etc. Here is a long list of them.
Perhaps of most interest to you would be Jetty, which is designed to be embedded into other applications. Use Jetty, rather than writing your own. It's a large undertaking to do a good job, and why reinvent the wheel?

Related

PSGI: What is it and what's the fuss about?

I have been trying to decide if my web project is a candidate for implementation using PSGI, but I don't really see what good it would do for my application at this stage.
I don't really understand all the fuss. To me PSGI seems like a framework that provides a common interface between different Apache modules which lets you move your application between them. e.g Easily move your application from running on mod_perl to fastcgi, and provide the application support for running on both options.
Is that right, or have I missed something?
As I and the team I am a part of not only develop the application, but also pretty much do maintenance and setup of servers I don't see the value for us of being able to run on fastcgi, cgi, and mod_perl, we do just fine with just mod_perl.
Have I misunderstood the PSGI functionality, or is it just not suitable for my project?
Forget the Apache bit. It's a way of writing your application so that the choice of webserver becomes less relevant. At $work we switched to Plack/PSGI after finding our app running with very high CPU load after upgrading to Apache2 - benchmarking various Apache configs and NYTProf'ing were unable to determine the reason, and using PSGI and the Starman webserver worked out much better for us.
Now everything is handled in one place by our PSGI app (URL re-writes, static content, expiry headers, etc) rather than Apache configuration, so it's a) Perl, and b) easily tested via our standard /t/ scripts. Also our tests are now testing exactly what a user sees, rather than just the basic app itself.
It may well not be relevant to you if you're happy with Apache and mod_perl, and I'm sure others will be able to give much better answers, but for us not having to deal with anything Apache-related again is such a relief in itself. The ease of testing, and the ability to just stick in a Data::Dumper and see what's going on rather than wrestling with ModRewrite and friends, is a great boon.
Borrowing from a recent blog post by chromatic, Why PSGI/Plack Matters (Testing), here's what it is:
It's a good idea borrowed from Python's WSGI and Ruby's Rack but made Perlish; it's a simple formalizing of a pattern of web application development, where the entry point into the application is a function reference and the exit point is a tuple of header information and a response body.
That's it. That's as simple as it can be, and that simplicity deceives a lot of people who want to learn it.
An important benefit is, ibid.,
Given a Plack application, you don't have to deploy to a web server—even locally—to test your application as if it were deployed … Plack and TWMP (and Plack::Test) use the well-defined Plack pattern to make something which was previously difficult into something amazingly easy. They're not the first and they won't be the last, but they do demonstrate the value of Plack.
Started wrote an answer and after 50 lines I deleted it. Simply because it is impossible tell (in short) why is PSGI extremely cool. I'm new in PSGI too, but zilion things now are much easier as before in my apache/mod_perl era.
I can give you next advices:
read the Plack advent calendar - all days, step-by-step. You must understand the basic philosophy, what is good on onions and so on... :)
search CPAN for "Plack::Middleware::" - and read the first few lines in each. Here are MANY. (Really should be somewhere some short overview for each one, unfortunately don't know any faster way. Simply it is good to know, what middlewares are already developed. (For example, you sure will need the Plack::Middleware::Session, or Plack::Middleware::Static and so on...)
read about Plack::Builder (already done, when you done with the advent calendar) :)
try write some apps with it and will find than Plack is like the first sex - now you didn't understand that you could live without it.
ps:
If was here something like "Perl Oscar", will sure nominating MyiagavaSan. :)

How to run Scala files on a web server

This could be either an incredibly easy or horrifically complicated question; but I've started writing code in Scala, and want to run said code on a web server.
There's a few questions that I need answering really, and I apologise for my complete lack of knowledge on the subject, web servers scare me (I'm a PHP developer so all I need to do there is upload to any linux apache server):
How to save and upload files (I know how to use ftp software, do I need to do anything from Eclipse?)
What to do to my server to run the files (at the moment I just have a linux apache server from fasthosts, is that enough?)
Any other advice would be so greatly appreciated; and the less jargon the better - the whole thing blags me a little.
UPDATE: To put the sort of work I'm doing into context, I'm making a rather large, social-media style site that'll have a very large amount of small, regular posts/updates. Also thanks for the answers so far!
Seems like i need to do all of the following:
Learn Scala (I can write in PHP and Java so should be okay)
Install Apache tomcat on my server somehow
Install Lift (and then either Maven or the SBT)
Upload the whole thing?
What do I do about databases?! I need something really serious, with MySQL be okay? Urgh this goes on and on...
Here are the most important points. I'm afraid you will not get this done without lots of reading, but at least you'll know where to start.
You need your own servlet container, e.g. Jetty or Tomcat. Those can be used as stand alone servers or together with apache.
You need to package your web application as a .war file. That is basically a zip file with all the classes and some meta information. Then you upload the .war file to the server.
You should have a look at a web framework for scala, such as Lift.
It also helps to be on good terms with one of the major build tools, sbt or maven.
You are better off using a framework - like Lift as the other answer suggest or...
Play framework has scala support as well - http://scala.playframework.org/
You can look at Play framework "Preparing for Production" page - http://www.playframework.org/documentation/1.0.2.1/guide11
It is not going to be like with PHP where you can just ftp and host.
Lift is a whole web development framework around Scala - might want to try their Getting Started page, or just poke around their docs in general.
But in general, you'll be using any of the java-based web application serving solutions, e.g. Jetty, Tomcat.
You have not said what exactly you want to do with Scala on the web. In addition to the Lift and Play frameworks there are some interesting alternatives like Unfiltered:
http://unfiltered.databinder.net/Unfiltered.html
https://github.com/n8han/Unfiltered
It is also easy to start without any kind of framework by directly writing Servlets:
Here is a interesting example that uses Jetty, websocktes and the Scala interpreter to create a web based Scala REPL:
https://github.com/TiarkRompf/replhtml
Also the excellent Akka framework has a http module:
http://akka.io/docs/akka/1.1.2/scala/http.html
Scalate
- http://scalate.fusesource.org/
To start with Scala without too much to read, you may give G-WAN v3.9 (that's the September beta, the release is expected in October) a try.
G-WAN runs Scala source code files without configuration (you just copy a file and call it) and it lets you run other languages the same way.

when people say they run 'scala in the backend', in what context could they be talking about?

Say the use scala to process incoming email etc.
In what context is (or could) they be running scala?
Can it run inside its own daemon?
Can it run inside of tomcat?
Or would you use it in a cron job?
or is it all of the above? :)
Sorry this is an open question, and I don't know much about scala, but I just want an idea of how one could utilize scala and under what context it can run in.
Scala is a general purpose language, and can be used pretty much everywhere that doesn't have restrictions of its own. One limitation it has is that it must be backed by a Java VM (or .Net if you go with the experimental stuff), which can bring limitations of its own.
When people said "backend", they usually mean using Scala to provide services to other software, leaving user-facing layers to other languages. This combination leverages the speed advantages of static typing in Scala, to benefits in the speed of development and interaction other languages -- PHP or Ruby, for example -- might provide for UI front ends.

learning and "singing" Ruby with Sinatra

Hello I'm trying to improve my ruby knowledge by reading The Ruby Programming Language book. Reading Coders at work I saw that lot of the interviewees suggest to dive into a project source code
to learn best practices
to be aware of bad habits
and of course to take new inspirations for how to do things.
I decided to pick a project as more self contained as I could find. My choice was Sinatra since It's 1000 LOC.
Is It a good project to learn?
Do you suggest another one more simple (i.e. less LOCs)?
I've tried to see rails machinery before but I came out scared from It.
I'm not that much into Ruby (although I've played a little bit with Sinatra), but I want to say that the Coders at Work advice should rather be read as "read source code not only from one project, but from many". We learn best by comparison. That's also how we're able to spot patterns and abstract them away.
So maybe you can choose some topic from Sinatra, see how it is implemented, then compare it with the way it's done in Rails.
The more sources you consider the better you understand a particular subject.
Reading the Sinatra code is a good start. You might also want to read up on Rack, the HTTP interface Sinatra uses. Not necessarily for coding practices but just to understand how Sinatra fits in the whole stack.
Adding to Ionuț's answer, Rails also uses Rack, so if you decide to look at both Sinatra and Rails, you can compare how they use Rack.
Try typing in gem list to list all the gems you've installed. Pick one that's relevant to your domain.

Advice for Beginners (Eclipse & Web Application)

I am about to start on a college project (a web application) and I have never used a full-fledged IDE such as Eclipse.
Turbo C/C++, Visual Basic 6,Java Basic, a bit of SQL, ASP, etc is the sort of exposure I have.
What things should I keep in mind before starting my project using Eclipse? Are the tools mentioned appropriate for the project?(If not please give a detailed answer)
Designing - UML (Rational Rose)
Language - Google Web Toolkit
Server - Google App Engine
IDE - Eclipse
Version Control - Subversion or Mercurial?
I would definitely recommend Googling first. There are a number of tutorials regarding Eclipse as it is a very popular IDE. A quick Google search of my own brought up all these results: developing web applications in eclipse
As for other things to consider, if you are developing a web application, you'll need:
web server (Tomcat is a popular one)
possibly a database (MySQL is an open source, easy to use DB)
language (I'm assuming you're going with Java since you are using Eclipse)
Of course, you'll also need to consider how you hook everything together and what technologies you want to use to do that. (Hibernate, Spring, etc) Eclipse itself has a ton of plugins to help bring together all these various aspects.
That list from Wikipedia is a good and comprehensive list, but if you are learning or developing on your own machine, you may not necessarily need all of that.
Hope that helps.
Since it is a web application, then start with the looks of it.
First, layout a template of how your pages should look, that is what users see. If it does not look good, the users will think the application (in its entirety) is also not good (it does not matter if the code behind the view is perfect; it will just make a first bad impression).
Start with that and be consistent with the design in all your pages. SiteMesh is a nice tool to dissociate the looks of the page from the functionality you put in it.
Then think what the application will do and what it will use:
you have a database? (use something like MySQL). With what are you going to access it? (IBatis is nice; Hibernate I think is a bit heavy weight for a first project)
you need a server: Tomcat is easy to use;
are you going for a simple Servlet/JSP approach or you want to use a framework (look at Spring or Struts);
try to find the good ways of writing the application, look at service layers, DAO pattern, DTO, MVC. Also, you must understand how HTTP works.
A lot more could be said.
Ah.. and also use a source repository. It’s a must (even if you work alone on this project).
Eclipse can handle all of these tools, but then so can Netbeans.
For your first project with GWT you should read through this tutorial:
http://code.google.com/webtoolkit/tutorials/1.6/gettingstarted.html
If you don't know Java then you will have some learning to do, and unlike Visual Studio your UI won't be just drag and drop, so it will be a bit harder than you are used to.
Subversion is fine, it is a nice source control, and any IDE will work with it.
Depending on your project would determine if GWT is the best choice though.
I expect UML may be overkill, and if you were following an agile methodology you wouldn't use it.
Your best bet is to get the UI done first, just have it appear as you want, and have some fake results, until you are happy with the look and feel.
Then, start to do the wiring to whatever you need on the backend.
Don't mean to be harping on you, but is Eclipse a must? For myself, in the beginning NetBeans turned out to be a really painless introduction to getting a web project up a running fast. I believe in the beginning one will spend a lot less time fighting the IDE with NetBeans.
A lot of the items from your bullet list NB makes super easy to ramp up as well. Just my $0.2