gob error encoding body: gob: type not registered for interface: in golang

Viewed 94

During RPC communication, the server cannot calculate the correct value.

I'm getting this error, and I've been thinking about it for a long time.

Can you give any advice

package main

import (
    "crypto/ecdsa"
    "crypto/elliptic"
    "crypto/rand"
    f "fmt"
    "log"
    "net"
    "net/rpc"
)

type Calc int //RPC 서버에 등록하기 위한 임의의 타입정의

type Args struct {
    A, B int
}
type Reply struct { //받을 값
    PrivateKey ecdsa.PrivateKey
    PublicKey  []byte
}

func (c *Calc) Get(args Args, reply *Reply) error {
    private, public := NewKeyPair()
    reply.PrivateKey = private
    reply.PublicKey = public

    return nil
}
func main() {
    rpc.Register(new(Calc))
    ln, err := net.Listen("tcp", ":6000")
    if err != nil {
        f.Println(err)
        return
    }
    defer ln.Close()

    for {
        conn, err := ln.Accept()
        if err != nil {
            continue
        }
        f.Println("Connected")
        defer conn.Close()
        go rpc.ServeConn(conn)
    }
}

func NewKeyPair() (ecdsa.PrivateKey, []byte) {
    curve := elliptic.P256()

    private, err := ecdsa.GenerateKey(curve, rand.Reader)
    if err != nil {
        log.Panic(err)
    }
    pubKey := append(private.PublicKey.X.Bytes(), private.PublicKey.Y.Bytes()...)

    return *private, pubKey
}

---- error ----

2022/06/20 19:58:35 rpc: gob error encoding body: gob: type not registered for interface: elliptic.p256Curve

0 Answers
Related