Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create protobuf server with go
openssl genrsa -out server.key 2048
openssl req -new -x509 -sha256 -key server.key -out server.crt -days 365
package main
import (
"net"
"crypto/tls"
)
func checkErr(err error){
if err != nil {
panic(err)
}
}
func handler(){
var err error
var n int
var b []byte = make([]byte, 1024)
n, err = conn.Read(b)
checkErr(err)
println("Reading", n, "bytes")
println(b)
}
func main(){
var err error
var ln net.Listener
var con net.Conn
var crt tls.Certificate
var config tls.Config
crt, err = tls.LoadX509KeyPair("server.crt", "server.key")
checkErr(err)
config = tls.Config{Certificates: []tls.Certificate{crt}}
ln, err = tls.Listen("tcp", ":9000", &config)
checkErr(err)
for {
conn, err = ln.Accept()
checkErr(err)
go handler(conn)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.