tcp

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2018 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Index = &ctx.Context{Name: "tcp", Help: "网络中心",
	Caches: map[string]*ctx.Cache{
		"nlisten": &ctx.Cache{Name: "监听数量", Value: "0", Help: "监听数量"},
		"nclient": &ctx.Cache{Name: "连接数量", Value: "0", Help: "连接数量"},
	},
	Configs: map[string]*ctx.Config{
		"security": &ctx.Config{Name: "加密通信(true/false)", Value: "false", Help: "加密通信"},
		"protocol": &ctx.Config{Name: "网络协议(tcp/tcp4/tcp6)", Value: "tcp4", Help: "网络协议"},
	},
	Commands: map[string]*ctx.Command{
		"listen": &ctx.Command{Name: "listen address [security [protocol]]", Help: "网络监听",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				m.Start(fmt.Sprintf("pub%d", Pulse.Capi("nlisten", 1)), "网络监听", m.Meta["detail"]...)
			}},
		"accept": &ctx.Command{Name: "accept address [security [protocol]]", Help: "网络连接",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				m.Start(fmt.Sprintf("com%d", Pulse.Capi("nclient", 1)), "网络连接", m.Meta["detail"]...)
			}},
		"dial": &ctx.Command{Name: "dial address [security [protocol]]", Help: "网络连接",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				m.Start(fmt.Sprintf("com%d", Pulse.Capi("nclient", 1)), "网络连接", m.Meta["detail"]...)
			}},
		"send": &ctx.Command{Name: "send message", Help: "发送消息",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				tcp, ok := m.Target().Server.(*TCP)
				m.Assert(ok && tcp.Conn != nil)
				tcp.Conn.Write([]byte(arg[0]))
			}},
		"recv": &ctx.Command{Name: "recv size", Help: "接收消息",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				tcp, ok := m.Target().Server.(*TCP)
				m.Assert(ok && tcp.Conn != nil)
				size, e := strconv.Atoi(arg[0])
				m.Assert(e)

				buf := make([]byte, size)
				tcp.Conn.Read(buf)
				m.Echo(string(buf))
			}},
		"ifconfig": &ctx.Command{Name: "ifconfig", Help: "接收消息",
			Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) {
				ifs, e := net.Interfaces()
				m.Assert(e)
				for _, v := range ifs {
					ips, e := v.Addrs()
					m.Assert(e)
					for _, x := range ips {
						m.Echo("%d %s %v %v\n", v.Index, v.Name, v.HardwareAddr, x.String())
					}
				}
			}},
	},
	Index: map[string]*ctx.Context{
		"void": &ctx.Context{
			Commands: map[string]*ctx.Command{
				"listen": &ctx.Command{},
				"dial":   &ctx.Command{},
			},
		},
	},
}
View Source
var Pulse *ctx.Message

Functions

This section is empty.

Types

type TCP

type TCP struct {
	net.Conn
	net.Listener
	*ctx.Context
}

func (*TCP) Begin

func (tcp *TCP) Begin(m *ctx.Message, arg ...string) ctx.Server

}}}

func (*TCP) Close

func (tcp *TCP) Close(m *ctx.Message, arg ...string) bool

}}}

func (*TCP) Spawn

func (tcp *TCP) Spawn(m *ctx.Message, c *ctx.Context, arg ...string) ctx.Server

func (*TCP) Start

func (tcp *TCP) Start(m *ctx.Message, arg ...string) bool

}}}

Jump to

Keyboard shortcuts

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