simplFT/server/server/connection.go

31 lines
530 B
Go
Raw Normal View History

2017-10-20 15:08:25 +00:00
package server
import (
"net"
"io"
"log"
"bufio"
)
func HandleConnection(c net.Conn) {
defer c.Close()
io.WriteString(c, "Hello and welcome to simple ftp\n")
log.Println(c.RemoteAddr(), "has connected.")
// Process input
input := bufio.NewScanner(c)
for input.Scan() {
log.Println(c.RemoteAddr(), ":", input.Text())
err := ProcessInput(c, input.Text())
if err != nil {
log.Println(err)
io.WriteString(c, err.Error()+"\n")
}
}
// Client has left.
log.Println(c.RemoteAddr(), "has disconnected.")
}