Skip to content

Instantly share code, notes, and snippets.

@o2gy84
Created April 2, 2020 12:30
Show Gist options
  • Save o2gy84/d6e692a5db9f1b2298c47961d06ae5b8 to your computer and use it in GitHub Desktop.
Save o2gy84/d6e692a5db9f1b2298c47961d06ae5b8 to your computer and use it in GitHub Desktop.
package main
import "net" import "fmt"
import "bufio"
import "os"
import "time"
func main() { conn, _ := net.Dial("tcp", "127.0.0.1:8081")
for {
reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
text, _ := reader.ReadString('\n')
fmt.Fprintf(conn, text + "\n")
var count = 0
for {
count++
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Printf("count: %d, Message from server: %s\n", count, message)
if count >= 1 {
fmt.Printf("close connection\n")
conn.Close()
break
} }
break
}
fmt.Printf("sleeping\n")
time.Sleep(time.Second * 60)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment