Test (very) basic networking.
This commit is contained in:
parent
ca3f1947b3
commit
fb77010302
|
@ -2,6 +2,8 @@ package cmd // code.bitsetter.de/fun/gosl/cmd
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
|
@ -15,8 +17,31 @@ var cmdServer = &cobra.Command{
|
|||
// Run:
|
||||
}
|
||||
|
||||
func handleConn(conn *net.TCPConn) {
|
||||
log.Println("Got a connection!")
|
||||
conn.Close()
|
||||
|
||||
}
|
||||
|
||||
func runServer(cmd *cobra.Command, args []string) {
|
||||
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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user