github.com/kaiya/goutils@v1.0.1-0.20230226104005-4ae4a4dc3688/tinyrpc/server/server.go (about)

     1  package main
     2  
     3  import (
     4  	"net"
     5  	"net/rpc"
     6  	"strconv"
     7  
     8  	"github.com/kaiya/goutils/tinyrpc/core"
     9  )
    10  
    11  func main() {
    12  	// Publish our Handler methods
    13  	rpc.Register(&core.Handler{})
    14  	Port := 3344
    15  
    16  	// Create a TCP listener that will listen on `Port`
    17  	listener, _ := net.Listen("tcp", ":"+strconv.Itoa(Port))
    18  
    19  	// Close the listener whenever we stop
    20  	defer listener.Close()
    21  
    22  	// Wait for incoming connections
    23  	rpc.Accept(listener)
    24  }