Guest User

Untitled

a guest
Jun 6th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.52 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "net"
  5.     "time"
  6.     "fmt"
  7. )
  8.  
  9. func main() {
  10.     l,e := net.Listen("tcp", "127.0.0.1:2222")
  11.     if e != nil {
  12.         panic(e)
  13.     }
  14.    
  15.     go func() {
  16.         c2,e2 := net.Dial("tcp", "127.0.0.1:2222")
  17.         if e2 != nil {
  18.             panic(e)
  19.         }
  20.         time.Sleep(time.Second*10)
  21.         c2.Write([]byte{1})
  22.     }()
  23.    
  24.     c,e := l.Accept()
  25.     if e != nil {
  26.         panic(e)
  27.     }
  28.    
  29.     c.SetReadDeadline(time.Time{}) //uncomment to make it work
  30.    
  31.     var buff [1024]byte
  32.     _,e = c.Read(buff[:])
  33.     if e != nil {
  34.         panic(e)
  35.     }
  36.    
  37.     fmt.Println(buff[0])
  38. }
Add Comment
Please, Sign In to add comment