27 lines
945 B
Kotlin
Raw Normal View History

2020-02-29 10:38:37 +01:00
package eu.heili.hometheater.website
import com.sun.net.httpserver.HttpServer
import eu.heili.hometheater.basicutils.Log.Log.criticalerror
import eu.heili.hometheater.basicutils.Log.Log.info
import java.io.IOException
import java.net.BindException
import java.net.InetSocketAddress
class Webserver {
fun startserver() {
info("starting Webserver")
try {
val server = HttpServer.create(InetSocketAddress(8080), 0)
server.createContext("/", MainPage())
// todo insert get and post request sites here!
server.executor = null // creates a default executor
server.start()
info("Server available at http://127.0.0.1:8080 now")
} catch (e: BindException) {
criticalerror("The Port 8080 is already in use!")
// todo option to choose other port
} catch (e: IOException) {
e.printStackTrace()
}
}
}