The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/api/proto/message/server.go

53 lines
1.2 KiB

package message
// This client service will replace the other client service.
// This client service will use unified Message.
// TODO(minhdoan): Refactor and clean up the other client service.
import (
context "context"
"log"
"net"
"google.golang.org/grpc"
)
// Constants for client service port.
const (
Port = "30000"
)
// Server is the Server struct for client service package.
type Server struct {
Port string
server *grpc.Server
}
6 years ago
// Process processes the Message and returns Response
func (s *Server) Process(ctx context.Context, message *Message) (*Response, error) {
return &Response{}, nil
}
// Start starts the Server on given ip and port.
func (s *Server) Start(ip, port string) (*grpc.Server, error) {
addr := net.JoinHostPort("", s.Port)
lis, err := net.Listen("tcp", addr)
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
var opts []grpc.ServerOption
s.server = grpc.NewServer(opts...)
RegisterClientServiceServer(s.server, s)
go s.server.Serve(lis)
return s.server, nil
}
6 years ago
// Stop stops the server.
func (s *Server) Stop() {
s.server.Stop()
}
6 years ago
// NewServer creates new Server which implements ClientServiceServer interface.
func NewServer() *Server {
return &Server{Port: Port}
}