Skip to content

Instantly share code, notes, and snippets.

@shanemhansen
Created June 21, 2012 05:01
Show Gist options
  • Save shanemhansen/2963924 to your computer and use it in GitHub Desktop.
Save shanemhansen/2963924 to your computer and use it in GitHub Desktop.
Go SSL Echo server
package main;
import "crypto/tls"
import "net"
import "fmt"
import "bufio"
func main() {
cert, err := tls.LoadX509KeyPair("/home/shane/.ssh/shared-space-node.crt",
"/home/shane/.ssh/shared-space-node.key")
config := tls.Config{Certificates: []tls.Certificate{cert}}
tcpListener, err := net.Listen("tcp", ":8080");
if err != nil {
fmt.Println("wtf")
}
listener := tls.NewListener(tcpListener, &config);
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println("awesome")
}
go handleClient(conn)
}
}
func handleClient(conn net.Conn) {
b := bufio.NewReader(conn)
for {
line, err := b.ReadBytes('\n')
if err != nil {
break
}
conn.Write(line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment