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
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

View File

@ -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)) + "}")