webrtc server development--build static page access service

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:
insert image description here
insert image description here

insert image description here

insert image description here
insert image description here

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

insert image description here

Guess you like

Origin blog.csdn.net/Redmoon955331/article/details/130066154