YHEchoPackage/ws/internal/server.go

29 lines
661 B
Go

/*
* 版权所有 (c) 上海元泓软件科技有限公司 2022.
* 严禁通过任何媒介未经授权复制本文件.
*
* 作者:mic
* Email:funui@outlook.com
*/
package internal
import (
"context"
"errors"
"fmt"
"github.com/panjf2000/gnet/v2"
)
func StartEcho(eventHandler gnet.EventHandler, network string, host string, port int) error {
if network == "ws" {
return gnet.Run(eventHandler, fmt.Sprintf("tcp://%s:%d", host, port), gnet.WithReusePort(true))
}
return errors.New(" only network ws!")
}
func StopEcho(network string, host string, port int) {
gnet.Stop(context.Background(), fmt.Sprintf("%s://%s:%d", network, host, port))
}