Documentation ¶
Index ¶
- Constants
- func Register(sockType SocketType, inst SocketInstance) (err error)
- func SetLogDebug(enable bool)
- func SetLogFile(strPath string)
- type Socket
- type SocketClient
- func (w *SocketClient) Close() (err error)
- func (w *SocketClient) Connect(url string) (err error)
- func (w *SocketClient) GetLocalAddr() (addr string)
- func (w *SocketClient) GetRemoteAddr() (addr string)
- func (w *SocketClient) IsClosed() bool
- func (w *SocketClient) Listen(url string) (err error)
- func (w *SocketClient) Recv(length int) (data []byte, from string, err error)
- func (w *SocketClient) Send(data []byte, to ...string) (n int, err error)
- type SocketHandler
- type SocketInstance
- type SocketServer
- func (w *SocketServer) Close()
- func (w *SocketServer) CloseClient(client *SocketClient) (err error)
- func (w *SocketServer) GetClientAll() (clients []*SocketClient)
- func (w *SocketServer) GetClientCount() int
- func (w *SocketServer) Listen(handler SocketHandler) (err error)
- func (w *SocketServer) Send(client *SocketClient, data []byte, to ...string) (n int, err error)
- type SocketType
Constants ¶
View Source
const ( URL_SCHEME_TCP = "tcp" URL_SCHEME_TCP4 = "tcp4" URL_SCHEME_TCP6 = "tcp6" URL_SCHEME_UDP = "udp" URL_SCHEME_UDP4 = "udp4" URL_SCHEME_UDP6 = "udp6" URL_SCHEME_WS = "ws" URL_SCHEME_WSS = "wss" URL_SCHEME_UNIX = "unix" )
View Source
const ( NETWORK_TCP = "tcp" NETWORK_TCPv4 = "tcp4" NETWORK_TCPv6 = "tcp6" NETWORK_UDP = "udp" NETWORK_UDPv4 = "udp4" NETWORK_UDPv6 = "udp6" NETWORK_UNIX = "unix" )
View Source
const ( WSS_TLS_CERT = "cert" WSS_TLS_KEY = "key" )
View Source
const (
PACK_FRAGMENT_MAX = 1500
)
Variables ¶
This section is empty.
Functions ¶
func Register ¶
func Register(sockType SocketType, inst SocketInstance) (err error)
func SetLogDebug ¶
func SetLogDebug(enable bool)
func SetLogFile ¶
func SetLogFile(strPath string)
Types ¶
type Socket ¶
type Socket interface { Listen() (err error) // bind and listen on address and port Accept() Socket // accept connection... Connect() (err error) // for tcp/web socket Send(data []byte, to ...string) (n int, err error) // send to... Recv(length int) (data []byte, from string, err error) // receive from... if length > 0, will receive the bytes specified. Close() (err error) // close socket GetLocalAddr() string // get socket local address GetRemoteAddr() string // get socket remote address GetSocketType() SocketType //get socket type }
type SocketClient ¶
type SocketClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient() *SocketClient
func (*SocketClient) Close ¶
func (w *SocketClient) Close() (err error)
func (*SocketClient) Connect ¶
func (w *SocketClient) Connect(url string) (err error)
IPv4 => tcp://127.0.0.1:6666 [tcp4://127.0.0.1:6666] WebSocket => ws://127.0.0.1:6668 [wss://127.0.0.1:6668]
func (*SocketClient) GetLocalAddr ¶
func (w *SocketClient) GetLocalAddr() (addr string)
func (*SocketClient) GetRemoteAddr ¶
func (w *SocketClient) GetRemoteAddr() (addr string)
func (*SocketClient) IsClosed ¶
func (w *SocketClient) IsClosed() bool
type SocketHandler ¶
type SocketHandler interface { OnAccept(c *SocketClient) OnReceive(c *SocketClient, data []byte, length int, from string) OnClose(c *SocketClient) }
type SocketInstance ¶
type SocketServer ¶
type SocketServer struct {
// contains filtered or unexported fields
}
func NewServer ¶
func NewServer(url string) *SocketServer
func (*SocketServer) Close ¶
func (w *SocketServer) Close()
func (*SocketServer) CloseClient ¶
func (w *SocketServer) CloseClient(client *SocketClient) (err error)
func (*SocketServer) GetClientAll ¶
func (w *SocketServer) GetClientAll() (clients []*SocketClient)
func (*SocketServer) GetClientCount ¶
func (w *SocketServer) GetClientCount() int
func (*SocketServer) Listen ¶
func (w *SocketServer) Listen(handler SocketHandler) (err error)
TCP => tcp://127.0.0.1:6666 UDP => udp://127.0.0.1:6667 WebSocket => ws://127.0.0.1:6668/ wss://127.0.0.1:6668/websocket?cert=cert.pem&key=key.pem
func (*SocketServer) Send ¶
func (w *SocketServer) Send(client *SocketClient, data []byte, to ...string) (n int, err error)
type SocketType ¶
type SocketType int
const ( SocketType_TCP SocketType = 1 SocketType_WEB SocketType = 2 SocketType_UDP SocketType = 3 SocketType_UNIX SocketType = 4 )
func (SocketType) GoString ¶
func (s SocketType) GoString() string
func (SocketType) String ¶
func (s SocketType) String() string
Click to show internal directories.
Click to hide internal directories.