Created
July 12, 2020 03:59
-
-
Save dipeshdulal/af42e16b9e002c92ecbaa3df52d1c2b4 to your computer and use it in GitHub Desktop.
Client Chat Main Function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var channelName = flag.String("channel", "default", "Channel name for chatting") | |
var senderName = flag.String("sender", "default", "Senders name") | |
var tcpServer = flag.String("server", ":5400", "Tcp server") | |
func main() { | |
flag.Parse() | |
fmt.Println("--- CLIENT APP ---") | |
var opts []grpc.DialOption | |
opts = append(opts, grpc.WithBlock(), grpc.WithInsecure()) | |
conn, err := grpc.Dial(*tcpServer, opts...) | |
if err != nil { | |
log.Fatalf("Fail to dail: %v", err) | |
} | |
defer conn.Close() | |
ctx := context.Background() | |
client := chatpb.NewChatServiceClient(conn) | |
go joinChannel(ctx, client) | |
scanner := bufio.NewScanner(os.Stdin) | |
for scanner.Scan() { | |
go sendMessage(ctx, client, scanner.Text()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment