我正在尝试将Play Framework网络服务器添加为大型应用程序的一部分,但该应用程序的主要用途不是Web服务器.它已经接受了各种连接,包括串行和TCP,但是我需要添加WebSocket,并且Play Framework的WebSocket接口是更可取的. (我们尝试过Undertow,但其笨拙的界面遇到了太多问题)
I'm trying to add a Play Framework web server as part of a larger application, but the application's primary purpose is NOT a web server. It already accepts a variety of connections, including serial and TCP, but I need to add WebSockets, and Play Framework's WebSocket interface is preferable. (We've tried Undertow, and encountered too many problems with its clunky interface)
我只能创建并启动一个应用程序,但是我无法连接到它.运行以下代码后,端口8000上没有任何监听.我需要做什么?
I've only gotten as far as creating an application, and starting it, but I'm unable to connect to it. After I run the following code, nothing is listening on port 8000. What do I need to do?
application.conf:
application.conf:
play.server.http.port=8000 http.port=8000webserver.scala:
webserver.scala:
def startWebServer = { val environment = new Environment( new File("/path/to/app"), classOf[Dummy].getClassLoader, play.api.Mode.Dev ) val context = play.api.ApplicationLoader.createContext(environment) val application = ApplicationLoader(context).load(context) play.api.Play.start(application) }build.sbt:
build.sbt:
libraryDependencies += "com.typesafe.play" %% "play" % "2.5.0-M1"输出:
[info] play.api.Play - Application started (Dev)您可以在此处下载代码: github/alancnet/playtest
You can download the code here: github/alancnet/playtest
推荐答案那只是应用程序.它仍然需要一个主机.添加以下代码:
That was just the application. It still needs a host. Add the following code:
webserver.scala:
webserver.scala:
play.core.server.NettyServer.fromApplication( application )build.sbt:
build.sbt:
libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.5.0-M1"输出:
[info] play.api.Play - Application started (Dev) [info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000这是投入生产的代码: gist.github/alancnet/68f6e787e1ab96bd1c4a
Here's the code that went into production: gist.github/alancnet/68f6e787e1ab96bd1c4a
更多推荐
使用Play Framework作为组件
发布评论