I'm trying to write a tcp server and multiple tcp clients. The tcp server is use grpc stream to send to all tcp client. My current solution is: On the grpc client code, just connect to the grpc stream. On the grpc stream server code::
func (s *rpcServer) DataStream(req *pb.SearchRequest, stream pb.SearchService_DataStreamServer) error {
for {
if data, ok := myMapData[req.ID]; ok {
stream.Send(data)
}
time.Sleep(time.Second)
}
}
This method is based on period time update. Is there better method if I create new data for some subscriber, then just send them?