Reputation:
I am trying to set up an http server using java. I am currently using the Vert.x package. This is my first experience with http server so i am kind of lost and don't really know how to proceed, hence i am seeking guidance. I have scrambled a a piece of code (probably not full) from some examples that i found on the subject.
public class SimpleFileServer extends AbstractVerticle {
private HttpServer httpServer = null;
@Override
public void start() throws Exception {
httpServer = vertx.createHttpServer();
httpServer.requestHandler(new Handler<HttpServerRequest>() {
@Override
public void handle(HttpServerRequest request) {
System.out.println("incoming request!");
Buffer fullRequestBody = Buffer.buffer();
if(request.method() == HttpMethod.POST){
request.handler(new Handler<Buffer>() {
@Override
public void handle(Buffer buffer) {
fullRequestBody.appendBuffer(buffer);
}
}
}
}
});
httpServer.listen(3030);
}}
i have many question on this matter, for example: what should be added to the code in order to send files (once every specific time interval) to the server? how can i check whether the server is working properly? assuming i don't have another computer to connect to it as a client? Should i try to set up TCP server instead?
I am basically seeking for any guidance on this matter, very basic stuff. any pointers, suggestions and good examples would be highly appreciated. thank you.
Upvotes: 0
Views: 631
Reputation: 5801
If you're looking for examples then I'd recommend you to have a look at the examples repo. It contains Hello World
size examples showing almost all the API.
From your code you can see in the core
examples how to make a HTTP server to handle file uploads. And the respective client code to upload to the server.
Of course the core
API is quite low level and there are easier and more productive ways to work with web applications, you should look at vertx-web examples.
Vertx-web covers almost all you need for modern web-apps from simple HTTP servers and routing to, realtime websockets and integration with javascript frameworks as Angular and React.
Upvotes: 0
Reputation: 93
Upvotes: 0