module

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommandMap map[string]string //处理用户的消息命令映射 key => funcName
View Source
var NowUserId int //全局uid

Functions

func UserRegister added in v1.0.5

func UserRegister() (uid int, uName string, uPhone string, uSex string)

注册一个新用户

Types

type ServerObj

type ServerObj struct {
	Ip        string
	Port      int
	OnlineMap map[int]*User //在线用户mapping

	Message chan string //总消息管道
	// contains filtered or unexported fields
}

func NewServer

func NewServer(ip string, port int) *ServerObj

进行初始化

func (*ServerObj) BroadCast

func (this *ServerObj) BroadCast(user *User, msg string)

进行消息广播

func (*ServerObj) Handler

func (this *ServerObj) Handler(conn net.Conn)

处理新用户链接 user指针写入mapping中 新加入用户消息金星广播

func (*ServerObj) ListenMessager

func (this *ServerObj) ListenMessager()

监听server消息管道,放到全部用户管道中

func (*ServerObj) Start

func (this *ServerObj) Start()

启动服务

type User

type User struct {
	Uid    int         //用户id
	Name   string      //客户端名称
	Phone  string      //手机号
	Addr   string      //客户端地址
	C      chan string //消息管道
	Conn   net.Conn    //socket链接
	Server *ServerObj  //客户端锁链接的server
}

func NewUser

func NewUser(conn net.Conn, server *ServerObj) *User

创建user对象api

func (*User) ExecMessage

func (this *User) ExecMessage(msg string)

处理用户发送的消息

func (*User) ListenServerMessage

func (this *User) ListenServerMessage()

监听server发送给user的消息

func (*User) Offline

func (this *User) Offline()

用户下线

func (*User) Online

func (this *User) Online()

用户上线

func (*User) SendMessage

func (this *User) SendMessage(msg string)

向单个用户发送消息

Jump to

Keyboard shortcuts

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