hello

package module
v0.0.0-...-616300c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 5 Imported by: 0

README

grpc-broadcast-example

gRPC broadcast example with BiDirectional streaming RPCs

Usage

First, run server/server.go then gRPC server listening on 0.0.0.0:50051.

$ go run server/server.go

Next run client/client.go with argument (client's name).

For example if you run 2 clients named 'Alice' and 'Bob', you will get the following output:

$ go run client/client.go Alice
$ go run client/client.go Bob
2019/10/01 21:00:04 new user: a85c7947-011e-4f0f-9805-ebe9ee2a9a3e
2019/10/01 21:00:04 broadcast: hello, I'm Alice
2019/10/01 21:00:05 broadcast: hello, I'm Alice
...
2019/10/01 21:00:20 new user: ac58baff-e689-4bfc-84e7-60149673079b
2019/10/01 21:00:20 broadcast: hello, I'm Bob
2019/10/01 21:00:21 broadcast: hello, I'm Alice
2019/10/01 21:00:21 broadcast: hello, I'm Bob
2019/10/01 21:00:22 broadcast: hello, I'm Alice
2019/10/01 21:00:22 broadcast: hello, I'm Bob
2019/10/01 21:00:23 broadcast: hello, I'm Alice
2019/10/01 21:00:23 broadcast: hello, I'm Bob
2019/10/01 21:00:24 broadcast: hello, I'm Alice
2019/10/01 21:00:24 broadcast: hello, I'm Bob
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterChatRoomServer

func RegisterChatRoomServer(s *grpc.Server, srv ChatRoomServer)

Types

type ChatRequest

type ChatRequest struct {
	Message              string   `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ChatRequest) Descriptor

func (*ChatRequest) Descriptor() ([]byte, []int)

func (*ChatRequest) GetMessage

func (m *ChatRequest) GetMessage() string

func (*ChatRequest) ProtoMessage

func (*ChatRequest) ProtoMessage()

func (*ChatRequest) Reset

func (m *ChatRequest) Reset()

func (*ChatRequest) String

func (m *ChatRequest) String() string

func (*ChatRequest) XXX_DiscardUnknown

func (m *ChatRequest) XXX_DiscardUnknown()

func (*ChatRequest) XXX_Marshal

func (m *ChatRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ChatRequest) XXX_Merge

func (m *ChatRequest) XXX_Merge(src proto.Message)

func (*ChatRequest) XXX_Size

func (m *ChatRequest) XXX_Size() int

func (*ChatRequest) XXX_Unmarshal

func (m *ChatRequest) XXX_Unmarshal(b []byte) error

type ChatResponse

type ChatResponse struct {
	Message              string   `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*ChatResponse) Descriptor

func (*ChatResponse) Descriptor() ([]byte, []int)

func (*ChatResponse) GetMessage

func (m *ChatResponse) GetMessage() string

func (*ChatResponse) ProtoMessage

func (*ChatResponse) ProtoMessage()

func (*ChatResponse) Reset

func (m *ChatResponse) Reset()

func (*ChatResponse) String

func (m *ChatResponse) String() string

func (*ChatResponse) XXX_DiscardUnknown

func (m *ChatResponse) XXX_DiscardUnknown()

func (*ChatResponse) XXX_Marshal

func (m *ChatResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ChatResponse) XXX_Merge

func (m *ChatResponse) XXX_Merge(src proto.Message)

func (*ChatResponse) XXX_Size

func (m *ChatResponse) XXX_Size() int

func (*ChatResponse) XXX_Unmarshal

func (m *ChatResponse) XXX_Unmarshal(b []byte) error

type ChatRoomClient

type ChatRoomClient interface {
	Chat(ctx context.Context, opts ...grpc.CallOption) (ChatRoom_ChatClient, error)
}

ChatRoomClient is the client API for ChatRoom service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewChatRoomClient

func NewChatRoomClient(cc *grpc.ClientConn) ChatRoomClient

type ChatRoomServer

type ChatRoomServer interface {
	Chat(ChatRoom_ChatServer) error
}

ChatRoomServer is the server API for ChatRoom service.

type ChatRoom_ChatClient

type ChatRoom_ChatClient interface {
	Send(*ChatRequest) error
	Recv() (*ChatResponse, error)
	grpc.ClientStream
}

type ChatRoom_ChatServer

type ChatRoom_ChatServer interface {
	Send(*ChatResponse) error
	Recv() (*ChatRequest, error)
	grpc.ServerStream
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL