阅读上一个主题 :: 阅读下一个主题 |
作者 |
正文 |
webdriver (只看此人)
|
时间: 2015-3-02 10:22
|
|
|
前言,网络/web时代,各种web框架层出不穷,最近看到有人提到 Vert.x 这么一个框架,据说跑在Java VM上,支持多种语言的Application共存,然后就看到对于一个简单Web Server的实现,各个语言的版本。
不看不知道,一看才知道自己有多Out了,居然有几个语言根本没听说过。
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
|
|
楼主 |
电梯直达
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:23
|
|
|
实现一:
代码: |
load('vertx.js')
vertx.createHttpServer().requestHandler(function(req) {
var file = req.path === '/' ? 'index.html' : req.path;
req.response.sendFile('webroot/' + file);
}).listen(8080)
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
|
|
沙发 |
返回顶端
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:23
|
|
|
实现二:
代码: |
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.deploy.Verticle;
public class Server extends Verticle {
public void start() {
vertx.createHttpServer().requestHandler(req -> {
String file = req.path.equals("/") ? "index.html" : req.path;
req.response.sendFile("webroot/" + file);
}).listen(8080);
}
}
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
板凳 |
返回顶端
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:24
|
|
|
Implementation 3:
代码: |
require "vertx"
Vertx::HttpServer.new.request_handler do |req|
file = req.uri == "/" ? "index.html" : req.uri
req.response.send_file "webroot/#{file}"
end.listen(8080)
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
地板 |
返回顶端
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:24
|
|
|
Implementation 4:
代码: |
vertx.createHttpServer().requestHandler { req ->
def file = req.uri == "/" ? "index.html" : req.uri
req.response.sendFile "webroot/$file"
}.listen(8080)
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
5 楼 |
返回顶端
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:25
|
|
|
Implementation 5:
代码: |
import vertx
server = vertx.create_http_server()
@server.request_handler
def handle(req):
filename = "index.html" if req.uri == "/" else req.uri
req.response.send_file("webroot/" + filename)
server.listen(8080)
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
6 楼 |
返回顶端
|
|
webdriver (只看此人)
|
时间: 2015-3-02 10:25
|
|
|
Implementation 6:
代码: |
(ns example.server
(:require [vertx.http :as http]))
(-> (http/server)
(http/on-request
(fn [req]
(let [uri (.uri req)]
(-> req
(http/server-response)
(http/send-file (str "webroot/" (if (= "/" uri) "index.html" uri)))))))
(http/listen 8080))
|
_________________ There is no wisdom tree; nor a stand of a mirror bright, Since all is void, where can the dust alight?
|
|
|
7 楼 |
返回顶端
|
|
本那比经略 (只看此人)
|
时间: 2015-3-02 12:09
|
|
|
在外人看来,这只不过是田里新长出来的一种作物,不管如何好看,终究是个蔬菜。。。:lol:
|
|
|
8 楼 |
返回顶端
|
|
名震一方 (只看此人)
|
时间: 2015-3-02 12:12
|
|
|
偶瞅着除了个别两个全是java。。 晕
_________________ |Pxz-Pzy| ≤ 1 + Pxy
Why is 6 so sad?
|
|
|
9 楼 |
返回顶端
|
|
nessus (只看此人)
|
时间: 2015-3-02 12:59
|
|
|
3,5,6都不知道是啥
|
|
|
10 楼 |
返回顶端
|
|
|