Created
April 2, 2020 12:30
-
-
Save o2gy84/d6e692a5db9f1b2298c47961d06ae5b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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