Test (very) basic networking.

This commit is contained in:
tkarrass 2016-01-19 16:51:50 +01:00
parent ca3f1947b3
commit fb77010302
2 changed files with 25 additions and 0 deletions

View File

@ -2,6 +2,8 @@ package cmd // code.bitsetter.de/fun/gosl/cmd
import ( import (
"fmt" "fmt"
"log"
"net"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -15,8 +17,31 @@ var cmdServer = &cobra.Command{
// Run: // Run:
} }
func handleConn(conn *net.TCPConn) {
log.Println("Got a connection!")
conn.Close()
}
func runServer(cmd *cobra.Command, args []string) { func runServer(cmd *cobra.Command, args []string) {
fmt.Println("running server ...") fmt.Println("running server ...")
listener, err := net.ListenTCP("tcp", &net.TCPAddr{Port: 8989})
if err != nil {
log.Fatal(err)
panic("Could not open Listener")
}
defer listener.Close()
for {
conn, err := listener.AcceptTCP()
if err != nil {
log.Fatal(err)
panic("Listener could not accept connection!")
}
go handleConn(conn)
}
data.TestNC() data.TestNC()
} }

BIN
gosl

Binary file not shown.