1 Star 0 Fork 0

leminewx/polarisprotocol

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
instance.go 1.03 KB
Copy Edit Raw Blame History
wenxian authored 2024-01-12 17:17 +08:00 . 优化协议
package main
import (
"fmt"
"net"
"os"
"os/signal"
"syscall"
"time"
"gitee.com/leminewx/polarisprotocol/v1/connection"
"gitee.com/leminewx/polarisprotocol/v1/model"
"gitee.com/leminewx/polarisprotocol/v1/protocol"
)
func main() {
conn, err := net.Dial("tcp", ":20771")
if err != nil {
panic(err)
}
// 认证
if err := connection.RequestAuth(conn, protocol.IDE_INSTANCE, "123qwe!@#"); err != nil {
panic(err)
}
c := connection.NewInstanceConn(conn)
c.RemoteIdentity = protocol.IDE_REGISTRAR
go func() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT) // 只接收INT信号(Ctrl+C)
<-sigChan
fmt.Println("Shutdowning...")
c.Unregister()
os.Exit(1)
}()
if err := c.Register(&model.Instance{
Id: "123qwe123",
Addr: "10.255.40.112:8879",
Name: "test",
Protocol: model.INS_PROTO_HTTP,
Namespace: "test",
ServiceName: "user",
ServiceVer: "v4",
}); err != nil {
conn.Close()
panic(err)
}
time.Sleep(10 * time.Second)
c.Unregister()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/leminewx/polarisprotocol.git
git@gitee.com:leminewx/polarisprotocol.git
leminewx
polarisprotocol
polarisprotocol
edd3e93176c7

Search