|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"strconv"
|
|
|
|
"FRMS/internal/pkg/reactor"
|
|
|
|
)
|
|
|
|
|
|
|
|
type coordinator interface {
|
|
|
|
Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCoordinator(ip string,port int,ch chan error) coordinator {
|
|
|
|
// allows interface checking as opposed to calling directly
|
|
|
|
return reactor.NewCoordinator(ip,port,ch)
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var ip string
|
|
|
|
var port int
|
|
|
|
|
|
|
|
flag.Usage = func() {
|
|
|
|
w := flag.CommandLine.Output()
|
|
|
|
fmt.Fprintf(w, "Usage: %s port \n",os.Args[0])
|
|
|
|
}
|
|
|
|
iptr := flag.String("i","192.168.100.2","ip address of server")
|
|
|
|
flag.Parse()
|
|
|
|
if flag.NArg() != 1 {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
args := flag.Args()
|
|
|
|
|
|
|
|
if p, err := strconv.Atoi(args[0]);p < 1024 || p > 65535 {
|
|
|
|
flag.Usage()
|
|
|
|
log.Fatal("Port must be between [1023,65535]")
|
|
|
|
} else if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
ip = *iptr
|
|
|
|
port, err := strconv.Atoi(args[0])
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
ch := make(chan error)
|
|
|
|
rlc := NewCoordinator(ip,port,ch) // host port
|
|
|
|
go rlc.Start()
|
|
|
|
err = <-ch
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|