minor update

This commit is contained in:
AJ ONeal 2018-07-29 17:04:05 -06:00
parent b87c005a9f
commit 434f72fa69
2 changed files with 11 additions and 6 deletions

View File

@ -11,13 +11,17 @@ go get gopkg.in/yaml.v2
# Usage # Usage
Start the server **Start the server**
```bash ```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 ```bash
telnet localhost 4080 telnet localhost 4080

View File

@ -77,7 +77,6 @@ func handleRaw(conn bufferedConn) {
// when it's being added here (data race)? // when it's being added here (data race)?
// Should I use a channel here instead? // Should I use a channel here instead?
// TODO see https://jameshfisher.com/2017/04/18/golang-tcp-server.html // TODO see https://jameshfisher.com/2017/04/18/golang-tcp-server.html
myRawConns[conn] = true
// Handle all subsequent packets // Handle all subsequent packets
buf := make([]byte, 1024) buf := make([]byte, 1024)
@ -189,6 +188,8 @@ func handleConnection(conn net.Conn) {
m.Lock() m.Lock()
if virgin { if virgin {
virgin = false virgin = false
// TODO probably needs to go into a channel
myRawConns[conn] = true
// don't block for this // don't block for this
// let it be handled after the unlock // 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") 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() { func main() {
flag.Usage = usage flag.Usage = usage
port := flag.Uint("telnet-port", 0, "tcp telnet chat port") 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() flag.Parse()
var config Conf var config Conf
confstr, err := ioutil.ReadFile(*confname) confstr, err := ioutil.ReadFile(*confname)
fmt.Fprintf(os.Stdout, "-config=%s\n", *confname) fmt.Fprintf(os.Stdout, "-conf=%s\n", *confname)
if nil != err { if nil != err {
fmt.Fprintf(os.Stderr, "%s\nUsing defaults instead\n", err) fmt.Fprintf(os.Stderr, "%s\nUsing defaults instead\n", err)
confstr = []byte("{\"port\":" + strconv.Itoa(int(*port)) + "}") confstr = []byte("{\"port\":" + strconv.Itoa(int(*port)) + "}")