github.com/devops-filetransfer/sshego@v7.0.4+incompatible/cmd/manual-unixdomain-recv/recv.go (about) 1 /* 2 a simple test receiver (server) to check that your 3 direct-tcpip connections are coming through the sshd. 4 See ../cmd/manual-test-client/client.go for the client part. 5 */ 6 package main 7 8 import ( 9 "fmt" 10 "net" 11 ) 12 13 func main() { 14 path := "/tmp/test-manual-unixdomain-recv" 15 lsn, err := net.Listen("unix", path) 16 panicOn(err) 17 fmt.Printf("\n listening on '%s'\n", lsn.Addr()) 18 19 tcpServerConn, err := lsn.Accept() 20 panicOn(err) 21 //fmt.Printf("%v\n", tcpServerConn) 22 23 payloadByteCount := 4 24 b := make([]byte, payloadByteCount) 25 n, err := tcpServerConn.Read(b) 26 panicOn(err) 27 if n != payloadByteCount { 28 panic(fmt.Errorf("read too short! got %v but expected %v", n, payloadByteCount)) 29 } 30 saw := string(b) 31 32 fmt.Printf("success! server got expected confirmation payload of '%s'\n", saw) 33 34 // reply back 35 n, err = tcpServerConn.Write([]byte("pong")) 36 panicOn(err) 37 if n != payloadByteCount { 38 panic(fmt.Errorf("write too short! got %v but expected %v", n, payloadByteCount)) 39 } 40 tcpServerConn.Close() 41 fmt.Printf("replied with 'pong'\n") 42 } 43 44 func panicOn(err error) { 45 if err != nil { 46 panic(err) 47 } 48 }