daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Jun 5th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import "net"
  4. import "log"
  5.  
  6. func main() {
  7.     ln, err := net.Listen("tcp", ":3000")
  8.     checkErr(err)
  9.     for {
  10.         conn, err := ln.Accept()
  11.         checkErr(err)
  12.         go handleConnection(conn)
  13.     }
  14. }
  15.  
  16. func handleConnection(conn net.Conn) {
  17.     incomingBytes := make([]byte, 256)
  18.     _, err := conn.Read(incomingBytes)
  19.     if err != nil {
  20.         conn.Close()
  21.         return
  22.     }
  23.     conn.Write(incomingBytes)
  24.     handleConnection(conn)
  25. }
  26.  
  27. func checkErr(err error) {
  28.     if err != nil {
  29.         log.Fatal("Error: ", err)
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top