使用Play Framework作为组件

编程入门 行业动态 更新时间:2024-10-28 14:24:21
本文介绍了使用Play Framework作为组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将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=8000

webserver.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作为组件

本文发布于:2023-07-11 17:10:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:组件   Play   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!