Skip to content

Commit

Permalink
改为明文传输
Browse files Browse the repository at this point in the history
  • Loading branch information
jxhczhl committed Apr 19, 2024
1 parent 3863ef5 commit e63dcd5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/gin-gonic/gin v1.9.1
github.com/gorilla/websocket v1.5.0
github.com/unrolled/secure v1.13.0
github.com/gorilla/websocket v1.5.1
github.com/sirupsen/logrus v1.9.3
github.com/unrolled/secure v1.14.0
)
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
log "github.com/sirupsen/logrus"
"github.com/unrolled/secure"
"net/http"
"os"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (w logWriter) Write(p []byte) (n int, err error) {
// is print?
func logPrint(p ...interface{}) {
if isPrint {
fmt.Println(p)
log.Infoln(p)
}
}

Expand Down Expand Up @@ -140,7 +141,7 @@ func GQueryFunc(client *Clients, funcName string, param string, resChan chan<- s
client.actionData[funcName] = make(chan string, 1) //此次action初始化1个消息
}
gm.Lock()
err := clientWs.WriteMessage(2, data)
err := clientWs.WriteMessage(1, data)
gm.Unlock()
if err != nil {
fmt.Println(err, "写入数据失败")
Expand Down Expand Up @@ -280,6 +281,7 @@ func main() {
}
// 将默认的日志输出器设置为空
//gin.DefaultWriter = logWriter{}
fmt.Println("欢迎使用jsrpc~")
gin.SetMode(gin.ReleaseMode)
r := gin.Default()
r.GET("/", Index)
Expand All @@ -292,9 +294,13 @@ func main() {
r.GET("/list", getList)
r.Use(TlsHandler())

//编译https版放开下面这行注释代码
//go func() {
// err := r.RunTLS(SSLPort, "zhengshu.pem", "zhengshu.key")
// if err != nil {
// fmt.Println(err)
// }
//}()
_ = r.Run(BasicPort)

//编译https版放开下面这行注释代码 并且把上一行注释
//_ = r.RunTLS(SSLPort, "zhengshu.pem", "zhengshu.key")

}
20 changes: 10 additions & 10 deletions resouces/JsEnv_Dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Hlclient.prototype.connect = function () {
try {
this.socket["ySocket"] = new WebSocket(this.wsURL);
this.socket["ySocket"].onmessage = function (e) {
try {
let blob = e.data
blob.text().then(data => {
_this.handlerRequest(data);
})
} catch {
console.log("not blob")
_this.handlerRequest(blob)
}

_this.handlerRequest(e.data)
// let blob = e.data
// try {
// blob.text().then(data => {
// _this.handlerRequest(data);
// })
// } catch {
// console.log("not blob")
// _this.handlerRequest(blob)
// }
}
} catch (e) {
console.log("connection failed,reconnect after 10s");
Expand Down

0 comments on commit e63dcd5

Please sign in to comment.