Exemplo n.º 1
0
func main() {

	if len(os.Args) < 3 {
		fmt.Fprintf(os.Stderr, "too few args,args form: <host port>\n")
		os.Exit(1)
	}
	host := os.Args[1]
	port, err := strconv.Atoi(os.Args[2])
	if err != nil {
		fmt.Fprintf(os.Stderr, "invalid port,need integer type,your input port: <port>\n", os.Args[2])
		os.Exit(1)
	}
	ctx := context.GetContext()
	currentServer := make(map[string]interface{})
	currentServer["id"] = "connector-1"
	currentServer["serverType"] = "connector"
	currentServer["host"] = "127.0.0.1"
	currentServer["port"] = 8888
	ctx.CurrentServer = currentServer
	defer seelog.Flush()

	tcp_cnct := tcp_connector.NewTcpConnector(host, port, nil)

	tcp_cnct.RegistNewConnCB(NewConnCB)
	tcp_cnct.RegistNewMsgCB(NewMsgCB)
	tcp_cnct.Start()
	ch := make(chan int)
	<-ch
}
Exemplo n.º 2
0
/// 获取CoConnector组件内部用于发送和接收消息的connector服务.
///
/// 如果用户配置了connector(保存在Context中),则使用全局配置的connector,
/// 否者使用默认的TcpConnector.
func getConnector(ctx *context.Context) connector.Connector {
	opts := ctx.AllOpts["coconnector"]
	if opts != nil {
		if c, setted := opts["connector"]; setted == true {
			if cnct, ok := c.(connector.Connector); ok == true {
				return cnct
			}
		}
	}

	curServer := ctx.CurrentServer
	host, _ := curServer["host"].(string)
	port := strconv.Itoa(curServer["port"].(int))
	return tcp_connector.NewTcpConnector(host, port, nil)
}