tcp_client

package module
v0.0.0-...-ec3dd07 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 3 Imported by: 0

README

tcp_client

Lib to create tcp clients faster

Usage:

package main

import client "github.com/WesleiRamos/tcp_client"

func main() {
	conexao := client.New("127.0.0.1:1232")

	conexao.OnOpen(func() {
		conexao.WriteString("EAE MAN")
		println("Conectou-se")
	})

	conexao.OnMessage(func(message []byte) {
		println("Menssagem: " + string(message))
	})

	conexao.OnError(func(err error) {
		if !conexao.Connected {
			panic(err)
		} else {
			println(err.Error())
		}
	})

	conexao.Listen()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Conn      net.Conn
	Address   string
	Connected bool
	// contains filtered or unexported fields
}

func New

func New(address string) *Connection

func (*Connection) Close

func (self *Connection) Close()

func (*Connection) Listen

func (self *Connection) Listen(addr string, auth *proxy.Auth) error

func (*Connection) OnError

func (self *Connection) OnError(f func(err error))

func (*Connection) OnMessage

func (self *Connection) OnMessage(f func(message []byte))

func (*Connection) OnOpen

func (self *Connection) OnOpen(f func())

func (*Connection) Write

func (self *Connection) Write(message []byte)

func (*Connection) WriteString

func (self *Connection) WriteString(message string)

Jump to

Keyboard shortcuts

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