IM-System版本0.9.3实现client更新用户名命令
This commit is contained in:
parent
2cb4cd4120
commit
ce1502d59c
@ -4,7 +4,9 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
@ -51,6 +53,19 @@ func (client *Client) menu() bool {
|
||||
}
|
||||
}
|
||||
|
||||
// client的更新用户名接口
|
||||
func (client *Client) UpdateName() bool {
|
||||
fmt.Println(">>>>>> 请输入新用户名:")
|
||||
fmt.Scanln(&client.Name)
|
||||
sendMsg := "rename|" + client.Name + "\n"
|
||||
_, err := client.conn.Write([]byte(sendMsg))
|
||||
if err != nil {
|
||||
fmt.Println("conn.Write err:", err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (client *Client) Run() {
|
||||
for client.flag != 0 {
|
||||
for !client.menu() {
|
||||
@ -67,10 +82,17 @@ func (client *Client) Run() {
|
||||
case 3:
|
||||
// 更新用户名
|
||||
fmt.Println("已选择更新用户名模式...")
|
||||
client.UpdateName()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理server回应的消息(直接显示到标准输出)
|
||||
func (client *Client) DealResponse() {
|
||||
// 一旦client.conn有数据就直接copy到stdout标准输出上,永久阻塞监听
|
||||
io.Copy(os.Stdout, client.conn)
|
||||
}
|
||||
|
||||
// 定义全局变量
|
||||
var serverIp string
|
||||
|
||||
@ -95,6 +117,9 @@ func main() {
|
||||
}
|
||||
fmt.Println(">>>>>> 连接服务器成功……")
|
||||
|
||||
// 单独开启一个goroutine去处理server发送的消息
|
||||
go client.DealResponse()
|
||||
|
||||
// for {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user