Article Directory
Followed by the previous section webrtc server development – setting up the environment
Create http server using go language
cd ~/dev/go
mkdir screen_share
cd screen_share
mkdir src
cd src
touch main.go
write go program
package main
import (
"fmt"
"net/http"
)
func main() {
// 1.定义一个 URL 前缀
staticURL := "/static/"
// 2.定义一个 FileServer
fs := http.FileServer(http.Dir("./static"))
// 3.绑定 url 和 FileServer
http.Handle(staticURL, http.StripPrefix(staticURL, fs))
// 4.启动 HttpServer
err := http.ListenAndServe(":8080",nil)
if err != nil {
fmt.Println(err)
}
}
compile
go build -o screen_share src/*
Create static html pages
Create a static directory
cd ~/dev/go/screen_share
mkdir static
touch share.html
write html program
<!DOCTYPE html>
<html>
hello rtc
</html>
Open port 8080 of a public IP of the cloud server
Proceed as follows:
Now the outside world can access port 8080 of this public network IP
start server
cd ~/dev/go/screen_share
./screen_share
Visit the share.html page in your browser
Enter public IP:8080//static/share.html in the search bar of the browser