Use Play Framework as a component

I am trying to add a Play Framework web server as part of a larger application, but the main purpose of the application is NOT a web server. It already accepts many connections, including serial and TCP, but I need to add WebSockets, and preferably the Play Framework WebSocket interface. (We tried Undertow and faced a lot of problems with its awkward interface)

I just got to creating the application and started it, but I can’t connect to it. After running the following code, port 8000 does not listen. What do I need to do?

application.conf:

play.server.http.port=8000 http.port=8000 

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:

 libraryDependencies += "com.typesafe.play" %% "play" % "2.5.0-M1" 

Output:

 [info] play.api.Play - Application started (Dev) 

You can download the code here: github.com/alancnet/playtest

+5
source share
1 answer

It was just an app. He still needs a host. Add the following code:

webserver.scala:

  play.core.server.NettyServer.fromApplication( application ) 

build.sbt:

 libraryDependencies += "com.typesafe.play" %% "play-netty-server" % "2.5.0-M1" 

output:

 [info] play.api.Play - Application started (Dev) [info] pcsNettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000 

EDIT: Here's the code that went into production: https://gist.github.com/alancnet/68f6e787e1ab96bd1c4a

+3
source

All Articles