Skip to content

Instantly share code, notes, and snippets.

@Poincare
Created November 9, 2013 16:02
Show Gist options
  • Save Poincare/7386885 to your computer and use it in GitHub Desktop.
Save Poincare/7386885 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
)
//notice that in the arguments, the name of
//the variable comes first, then comes the
//type of the variable, just like in "var"
//declarations
func manageClient(conn net.Conn) {
conn.Write([]byte("Hi!"))
conn.Close()
//do something with the client
}
func main() {
//we are creating a server her that listens
//on port 1337. Notice that, similar to Ruby,
//a method can have two return values (although
//in Ruby, this would be an array instead)
listener, err := net.Listen("tcp", ":1337")
for {
//accept a connection
connection, _ := listener.Accept()
go manageClient(connection)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment