Files
mettler-toledo/server.go

59 lines
971 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"net"
"os"
)
const (
CONN_HOST = "192.168.8.177"
CONN_PORT = "3333"
CONN_TYPE = "tcp"
CONN_URL = CONN_HOST + ":" + CONN_PORT
)
func main() {
// Listen for incoming connections
l, err := net.Listen(CONN_TYPE, CONN_URL)
if err != nil {
fmt.Println("Error listening:", err.Error())
os.Exit(1)
}
// Close the listener when this application closes
defer l.Close()
fmt.Println("Listening on " + CONN_URL)
for {
// Listen for connections
conn, err := l.Accept()
if err != nil {
fmt.Println("Error accepting connection:", err.Error())
os.Exit(1)
}
go handleRequest(conn)
}
}
func handleRequest(conn net.Conn) {
// Buffer that holds incoming information
buf := make([]byte, 1024)
for {
len, err := conn.Read(buf)
if err != nil {
fmt.Println("Error reading:", err.Error())
break
}
s := string(buf[:len])
fmt.Println(s)
}
}