Created
November 9, 2013 16:02
-
-
Save Poincare/7386885 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 ( | |
"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