diff --git a/README.md b/README.md index 96387cb..29acb87 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,17 @@ go get gopkg.in/yaml.v2 # Usage -Start the server +**Start the server** ```bash -go run chatserver.go +go run chatserver.go -conf ./config.yml ``` -Connect with another client or three. +See sample config file at `config.sample.yml`. + +**Connect clients** + +You can connect multiple clients. ```bash telnet localhost 4080 diff --git a/chatserver.go b/chatserver.go index e12c466..ad3e2e2 100644 --- a/chatserver.go +++ b/chatserver.go @@ -77,7 +77,6 @@ func handleRaw(conn bufferedConn) { // when it's being added here (data race)? // Should I use a channel here instead? // TODO see https://jameshfisher.com/2017/04/18/golang-tcp-server.html - myRawConns[conn] = true // Handle all subsequent packets buf := make([]byte, 1024) @@ -189,6 +188,8 @@ func handleConnection(conn net.Conn) { m.Lock() if virgin { virgin = false + // TODO probably needs to go into a channel + myRawConns[conn] = true // don't block for this // let it be handled after the unlock defer fmt.Fprintf(conn, "Welcome! This is an open relay chat server. There is no security yet.\n") @@ -199,12 +200,12 @@ func handleConnection(conn net.Conn) { func main() { flag.Usage = usage port := flag.Uint("telnet-port", 0, "tcp telnet chat port") - confname := flag.String("config", "./config.yml", "ymal config file") + confname := flag.String("conf", "./config.yml", "yaml config file") flag.Parse() var config Conf confstr, err := ioutil.ReadFile(*confname) - fmt.Fprintf(os.Stdout, "-config=%s\n", *confname) + fmt.Fprintf(os.Stdout, "-conf=%s\n", *confname) if nil != err { fmt.Fprintf(os.Stderr, "%s\nUsing defaults instead\n", err) confstr = []byte("{\"port\":" + strconv.Itoa(int(*port)) + "}")