Exemplo n.º 1
0
func main() {

	var cfgFile = "msgsrvr.cfg"
	HOST, PORT, errFile := configfile.GetHostPort(cfgFile)
	if errFile != nil {
		fmt.Println(errFile.Error())
		fmt.Println("Unable to read configuration from file :" + cfgFile)
		return
	}

	service := "ws://" + HOST + ":" + PORT

	if len(os.Args) > 1 {
		service += "/" + os.Args[1]
	} else {
		service += "/"
	}

	//Connect
	conn, err := websocket.Dial(service, "", "http://"+HOST)
	checkError(err)

	//Send
	smsg := locationUpdate()
	err = websocket.Message.Send(conn, smsg)
	checkError(err)

	//Receive
	var rmsg string
	err = websocket.Message.Receive(conn, &rmsg)
	checkError(err)
	fmt.Println("Received: " + rmsg)

	os.Exit(0)
}
Exemplo n.º 2
0
func main() {
	var cfgFile = "msgsrvr.cfg"
	HOST, PORT, errFile := configfile.GetHostPort(cfgFile)
	if errFile != nil {
		fmt.Println(errFile.Error())
		fmt.Println("Unable to read configuration from file :" + cfgFile)
		return
	}

	service := "ws://" + HOST + ":" + PORT + "/iPad"

	var who string

	if len(os.Args) > 1 {
		who = os.Args[1]
	} else {
		who = "ALFONSO"
	}

	//Connect
	conn, err := websocket.Dial(service, "", "http://"+HOST)
	checkError(err)

	fmt.Println("Connected")

	err = websocket.Message.Send(conn, who)
	checkError(err)

	for {
		//Receive
		var rmsg string
		err = websocket.Message.Receive(conn, &rmsg)
		checkError(err)
		fmt.Println("Received:")
		fmt.Println(rmsg)
	}

}
Exemplo n.º 3
0
func main() {

	var cfgFile = "msgsrvr.cfg"
	_, PORT, errFile := configfile.GetHostPort(cfgFile)
	if errFile != nil {
		fmt.Println(errFile.Error())
		fmt.Println("Unable to read configuration from file :" + cfgFile)
		return
	}

	msgQ.initQ()

	go msgQ.doDBQ()

	http.Handle("/PubSub", websocket.Handler(PubSub))
	http.Handle("/Subscribe", websocket.Handler(Subscribe))
	http.Handle("/itelPublishOnce", websocket.Handler(itelPublishOnce))
	http.Handle("/Publish", websocket.Handler(Publish))
	http.HandleFunc("/exit", exit_handler)
	http.Handle("/", websocket.Handler(rootH))
	err := http.ListenAndServe(":"+PORT, nil)
	checkError(err)
}