Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/evindunn/gtcp

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/evindunn/gtcp

  • v0.0.0-20200105191042-6a16c2e2455e
  • Source
  • Go
  • Socket score

Version published
Created
Source

GoLang TCP

gotest-status gotest-status Coverage Status Go report card License

Simple TCP message passing in Go

API
  • github.com/evindunn/gtcp/pkg/tcpclient
    • Send(addrStr string, msgStr string) error
  • github.com/evindunn/gtcp/pkg/tcpserver
    • NewServer(port int, handler ConnectionHandler) (*Server, error)
    • Server.Start()
  • github.com/evindunn/gtcp/pkg/tcpmessage
    • NewMessage(content string, isCompressed bool) Message
    • MessageFromConnection(c *net.Conn) (*Message, error)
    • Message.ToBytes() []byte
    • Message.GetContent() []byte
    • Message.GetSize() int
    • Message.IsCompressed() bool
    • Message.Compress() error
    • Message.Decompress() error
Examples

Handle connections using the interface defined in ConnectionHandler.go

type Handler struct {}

// This method makes the Handler type implement the ConnectionHandler interface
func (h *Handler) HandleConnection(c *net.Conn) {
    defer (*c).Close()
    log.Println("Connected!")
}

Then use the handler with the Server struct

var h Handler
srv, err := tcpServer.NewServer(8080, &h)

if err != nil {
    fmt.Fprintf(os.Stderr, "An error occurred creating the server: %s\n", err)
    os.Exit(1)
}

srv.Start()

The Message class defines a simple protocol for passing messages in TCP

|------- 8 bytes---------|------- 1 byte ---------|------- Remaining bytes ---------|
|----- messageSize ------|----- isCompressed -----|---------- content --------------|

FAQs

Package last updated on 05 Jan 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc