Skip to content

cloudlink-delta/duplex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

banner

Duplex

A minimal, Go-based library to run CL∆ clients or servers.

Example Usage

package main

import (
    // ...
    "github.com/cloudlink-delta/duplex"
)

func main() {

    // Creates a new duplex instance with a unique name.
    instance := duplex.New("my server")

    // Overrides the default behavior of a built-in CL Delta opcode.
    // Remapped functions have the highest priority during processing.
    instance.Remap("G_MSG", func(peer *duplex.Peer, packet *duplex.RxPacket) {
		// ...
	})

    // If you want to switch back to the built-in behavior of a opcode...
    instance.Unmap("G_MSG")

    // Creates a new opcode handler.
    // Custom handlers have the lowest priority during processing.
    // Any remapped or built-in handlers will run first.
    instance.Bind("MY_OPCODE", func(peer *duplex.Peer, packet *duplex.RxPacket) {
		// ...
	})

    // If you need to remove a custom handler...
    instance.Unbind("MY_OPCODE")

    // To run the instance, simply call Run().
    // Note that Run() will block code execution.
    instance.Run()
}

About

Minimal Go-based library to run CL∆ clients or servers.

Resources

License

Stars

Watchers

Forks

Languages