Skip to content

Instantly share code, notes, and snippets.

@Yapcheekian
Created May 25, 2021 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yapcheekian/d1f5bd693d264f555e0da7c826eabff3 to your computer and use it in GitHub Desktop.
Save Yapcheekian/d1f5bd693d264f555e0da7c826eabff3 to your computer and use it in GitHub Desktop.
Example client in go
package main
import "net"
import "fmt"
import "bufio"
import "os"
func main() {
// connect to this socket
conn, _ := net.Dial("tcp", "127.0.0.1:8081")
for {
// read in input from stdin
reader := bufio.NewReader(os.Stdin)
fmt.Print("Text to send: ")
text, _ := reader.ReadString('\n')
// send to socket
fmt.Fprintf(conn, text + "\n")
// listen for reply
message, _ := bufio.NewReader(conn).ReadString('\n')
fmt.Print("Message from server: "+message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment