roshan

package module
v0.0.0-...-6384d94 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 14 Imported by: 0

README

roshan

this is a tcp communication design and implement. it is easy to reuse in other project.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	//SocketConnected socket connected
	SocketConnected func(conn net.Conn)
	//BeforeClose before close the socket
	BeforeClose func(conn net.Conn)
	// contains filtered or unexported fields
}

Client tcpserver client

func NewClient

func NewClient() *Client

NewClient create client

func (*Client) AddHandler

func (sc *Client) AddHandler(msgType message.CmdType, handler handler.Handler)

AddHandler add handler for message

func (*Client) Close

func (client *Client) Close()

Close close the connection

func (*Client) Connect

func (client *Client) Connect(ip string, port int) bool

Connect connect to server

func (*Client) SetSK

func (sc *Client) SetSK(key string)

set security key(use aes, ctr mode)

func (*Client) Transmit

func (sc *Client) Transmit(para *handler.CommObj)

Transmit send message to handler

type Server

type Server struct {

	//BeforeAccept before accept socket(this is not the same with ConnectMessage), you can do something such as stop or block continue accept
	BeforeAccept func()
	//SocketAccepted accept socket
	SocketAccepted func(conn net.Conn)
	// contains filtered or unexported fields
}

Server tcp server struct

func NewServer

func NewServer() *Server

NewServer create new tcp server

func (*Server) AddHandler

func (sc *Server) AddHandler(msgType message.CmdType, handler handler.Handler)

AddHandler add handler for message

func (*Server) CloseListen

func (server *Server) CloseListen()

CloseListen close listen

func (*Server) SetSK

func (sc *Server) SetSK(key string)

set security key(use aes, ctr mode)

func (*Server) Start

func (server *Server) Start(port int)

Start start tcp server

func (*Server) StartHandlePacket

func (server *Server) StartHandlePacket(conn net.Conn)

StartHandlePacket continue to handle packet after receive some special command packet such as connectmessage, you can start or stop handle command and data packet

func (*Server) StopAccept

func (server *Server) StopAccept()

StopAccept stop continue accept socket

func (*Server) StopHandlePacket

func (server *Server) StopHandlePacket(conn net.Conn)

StopHandlePacket stop handle command and data packet

func (*Server) Transmit

func (sc *Server) Transmit(para *handler.CommObj)

Transmit send message to handler

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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