当前位置: 首页 > 工具软件 > Kitex > 使用案例 >

kitex 框架,解决端口冲突

卜昂熙
2023-12-01
package main

import (
	"log"

	"net"
	api "github.com/cloudwego/kitex-examples/hello/kitex_gen/api/hello"
	"github.com/cloudwego/kitex/server"
)

func main() {

	addr, _ := net.ResolveTCPAddr("tcp", ":8801")

	var opts []server.Option
	opts = append(opts, server.WithServiceAddr(addr))

	svr := api.NewServer(new(HelloImpl), opts...)

	err := svr.Run()
	if err != nil {
		log.Println(err.Error())
	}
}

kitex的默认端口是8888,不修改会报错

2021/12/01 21:12:03.019779 server.go:79: [Info] KITEX: server listen at: :8888
2021/12/01 21:12:03.029125 server.go:187: [Error] KITEX: received error and exit: listen tcp :8888: bind: address already in use
2021/12/01 21:12:03 listen tcp :8888: bind: address already in use
 类似资料: