MCPcopy Index your code
hub / github.com/OvenVan/chitchat

github.com/OvenVan/chitchat @v1.0.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.2 ↗ · + Follow
88 symbols 144 edges 5 files 3 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

chitchat

-- import "github.com/ovenvan/chitchat"

What's this: This is a lightweight, support for high-concurrency communication Library framework, based on golang socket.

What's demo.go/demo_test.go: This is an simple Demo that tells you how to use this framework.


Usage

Whether for server or client, it only takes three steps to get it worked properly: 1. Tell it the address of the registration (listening); 2. Tell it how to process the data after reading it; 3. Correct handling Error notifications.

For Server:

type Server interface {
    Listen() error
    Cut() error
    CloseRemote(string) error
    RangeRemoteAddr() []string
    GetLocalAddr() string
    SetDeadLine(time.Duration, time.Duration)
    ErrChan() <-chan Errsocket
    Write(interface{}) error
}

func NewServer

func NewServer(
    ipaddrsocket string,
    delim byte, readfunc ServerReadFunc, additional interface{}) Server

The method of registering the server with the framework. All you need to do is to tell the framework the 1. IP address(Addr:Port) being monitored, 2. the delimiter of one sentence, 3. the Read method, 4. and the additional information (could be nil).

if the delimiter is 0, then the framework will NOT send sentence to readfunc until EOF.

func Listen

func Listen() error

The method does not block the process, it asynchronously initiates the relevant goroutine to ensure that the framework works properly. At this point, Server is ready to start normally.

func Cut

func Cut() error

Terminates the listening service.

func CloseRemote

func CloseRemote(remoteAddr string) error

Closes a connection for a specific IP. If the connection to the IP does not exist, an error will be returned.

func RangeRemoteAddr

func RangeRemoteAddr() []string

Returns all the connections.

func ErrChan

func ErrChan() <-chan Errsocket

Returns the channel allows consumers to receive errors.

...(some other funcs defined in server interface)

For Client:

type Client interface {
    Dial() error
    Close()
    SetDeadLine(time.Duration)
    ErrChan() <-chan Errsocket
    Write(interface{}) error
    GetRemoteAddr() string
    GetLocalAddr() string
}

func NewClient

func NewClient(
    ipremotesocket string,
    delim byte, readfunc ClientReadFunc, additional interface{}) Client {

Same as NewServer. however, the readfunc can be set nil.

func Dial() error

func Dial() error

Allows clients to connect to the remote server. You cannot manually select your own IP address for the time being, but you can obtain it through the GetLocalAddr () method. This method does not block the process.

func SetDeadLine(time.Duration)

func SetDeadLine(dDDL time.Duration)

This function works before Dial(). It specifies the maximum time for the connection.

How to write READ FUNC?

When the framework reads the separator, he hands over what he has previously read to the user-defined read func.

For Server and Client, their ReadFunc is the same, however with different names.

type ServerReadFunc func([]byte, ReadFuncer) error
type ClientReadFunc func([]byte, ReadFuncer) error

If you need to use additional parameters, you can get it through t.Addon ().

This parameter was already given (additional) when the Server (Client) was initialized. If the time is set to a null value, additional parameters cannot be obtained by the Addon method at this time.

Limitations of Write

The Write method encodes any transmitted data through JSON. You can decode it through the Unmarshal() function when you need it. The Write method automatically supplements the separator for you, so you don't need to artificially add delimiters.

However If the Write method provided by the framework does not suit you, you can replace it with the ' SetWriteFunc () ' function.

Demo

A simple heartbeat detection package.

For More info

如何使用golang - chitchat

Extension points exported contracts — how you extend this code

MasterRoler (Interface)
(no doc) [2 implementers]
demo.go
ReadFuncer (Interface)
(no doc) [2 implementers]
common.go
Server (Interface)
(no doc) [1 implementers]
server.go
Client (Interface)
(no doc) [1 implementers]
client.go
NodeRoler (Interface)
(no doc) [1 implementers]
demo.go
ServerReadFunc (FuncType)
(no doc)
server.go
ClientReadFunc (FuncType)
(no doc)
client.go

Core symbols most depended-on inside this repo

Close
called by 5
client.go
Listen
called by 3
server.go
iportSplitter
called by 3
demo.go
Dial
called by 3
client.go
NewServer
called by 2
server.go
errDiversion
called by 2
common.go
read
called by 2
common.go
Write
called by 2
client.go

Shape

Method 51
Function 18
Struct 10
Interface 5
FuncType 4

Languages

Go100%

Modules by API surface

server.go27 symbols
client.go22 symbols
demo.go21 symbols
common.go17 symbols
demo_test.go1 symbols

For agents

$ claude mcp add chitchat \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page