Documentation ¶
Index ¶
- Constants
- func PacketHandler(s ITransport)
- func RunClientTCP()
- func RunClientUDP()
- func RunServerTCP()
- func RunServerUDP()
- type Connection
- type IClient
- type IServer
- type ITransport
- type Packet
- type Statistic
- type TCPClient
- func (c *TCPClient) Close() error
- func (s *TCPClient) Conn() *Connection
- func (c *TCPClient) Heartbeat(p *Packet)
- func (c *TCPClient) IsReliable() bool
- func (c *TCPClient) LocalAddr() net.Addr
- func (c *TCPClient) Name() string
- func (c *TCPClient) ReadPacketChan() <-chan *Packet
- func (c *TCPClient) RemoteAddr() net.Addr
- func (c *TCPClient) StartAndWait() error
- func (c *TCPClient) WritePacket(packet *Packet)
- type TCPServer
- func (s *TCPServer) Close() error
- func (s *TCPServer) CloseOne(addr string)
- func (s *TCPServer) Conn() *Connection
- func (s *TCPServer) IsKeepalive() bool
- func (s *TCPServer) IsReliable() bool
- func (s *TCPServer) Name() string
- func (s *TCPServer) ReadPacketChan() <-chan *Packet
- func (s *TCPServer) StartAndWait() error
- func (s *TCPServer) WritePacket(packet *Packet)
- type UDPClient
- func (c *UDPClient) Close() error
- func (c *UDPClient) Conn() *Connection
- func (c *UDPClient) Heartbeat(p *Packet)
- func (c *UDPClient) IsReliable() bool
- func (c *UDPClient) LocalAddr() net.Addr
- func (c *UDPClient) Name() string
- func (c *UDPClient) ReadPacketChan() <-chan *Packet
- func (c *UDPClient) RemoteAddr() net.Addr
- func (c *UDPClient) StartAndWait() error
- func (c *UDPClient) WritePacket(packet *Packet)
- type UDPServer
- func (s *UDPServer) Close() error
- func (s *UDPServer) CloseOne(addr string)
- func (s *UDPServer) Conn() *Connection
- func (s *UDPServer) IsKeepalive() bool
- func (s *UDPServer) IsReliable() bool
- func (s *UDPServer) Name() string
- func (s *UDPServer) ReadPacketChan() <-chan *Packet
- func (s *UDPServer) StartAndWait() error
- func (s *UDPServer) WritePacket(packet *Packet)
Constants ¶
View Source
const SipHost string = "127.0.0.1"
默认端口:TCP/UDP是5060,5061是在TCP上的TLS 对于服务器监听UDP的任何端口和界面,都必须在TCP上也进行同样的监听。这是因为可能消息还需要通过TCP进行传输,比如消息过大的情况。
View Source
const SipPort uint16 = 5060
Variables ¶
This section is empty.
Functions ¶
func PacketHandler ¶
func PacketHandler(s ITransport)
func RunClientUDP ¶
func RunClientUDP()
func RunServerTCP ¶
func RunServerTCP()
func RunServerUDP ¶
func RunServerUDP()
Types ¶
type Connection ¶
type Connection interface { net.Conn Network() string // String() string ReadFrom(buf []byte) (num int, raddr net.Addr, err error) WriteTo(buf []byte, raddr net.Addr) (num int, err error) }
Connection Wrapper around net.Conn.
type IClient ¶
type IClient interface { ITransport LocalAddr() net.Addr //本地地址 RemoteAddr() net.Addr //远程地址 Heartbeat(packet *Packet) //客户端需要定期发送心跳包到服务器端 }
transport 需要实现的接口如下
func NewTCPClient ¶
func NewUDPClient ¶
type IServer ¶
type IServer interface { ITransport CloseOne(addr string) //对于关闭某个客户端连接,比如没有鉴权的非法链接,心跳超时等 IsKeepalive() bool //persistent connection or not }
func NewTCPServer ¶
func NewUDPServer ¶
type ITransport ¶
type TCPClient ¶
type TCPClient struct { Statistic // contains filtered or unexported fields }
func (*TCPClient) Conn ¶ added in v3.0.4
func (s *TCPClient) Conn() *Connection
func (*TCPClient) IsReliable ¶
func (*TCPClient) ReadPacketChan ¶
func (*TCPClient) RemoteAddr ¶
func (*TCPClient) StartAndWait ¶ added in v3.0.4
func (*TCPClient) WritePacket ¶
type TCPServer ¶
func (*TCPServer) Conn ¶ added in v3.0.4
func (s *TCPServer) Conn() *Connection
func (*TCPServer) IsKeepalive ¶
func (*TCPServer) IsReliable ¶
func (*TCPServer) ReadPacketChan ¶
func (*TCPServer) StartAndWait ¶ added in v3.0.4
func (*TCPServer) WritePacket ¶
type UDPClient ¶
type UDPClient struct { Statistic // contains filtered or unexported fields }
func (*UDPClient) Conn ¶ added in v3.0.4
func (c *UDPClient) Conn() *Connection
func (*UDPClient) IsReliable ¶
func (*UDPClient) ReadPacketChan ¶
func (*UDPClient) RemoteAddr ¶
func (*UDPClient) StartAndWait ¶ added in v3.0.4
func (*UDPClient) WritePacket ¶
type UDPServer ¶
func (*UDPServer) Conn ¶
func (s *UDPServer) Conn() *Connection
func (*UDPServer) IsKeepalive ¶
func (*UDPServer) IsReliable ¶
func (*UDPServer) ReadPacketChan ¶
func (*UDPServer) StartAndWait ¶ added in v3.0.4
func (*UDPServer) WritePacket ¶
Click to show internal directories.
Click to hide internal directories.