udpclient

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2022 License: MIT Imports: 4 Imported by: 8

README

UDP Client Go Reference

UDP client for Go

Example

Send a status 23 command to a QuakeWorld server.

package main

import (
	"github.com/vikpe/udpclient"
)

func main() {
	client := udpclient.New()
	statusPacket := []byte{0xff, 0xff, 0xff, 0xff, 's', 't', 'a', 't', 'u', 's', ' ', '2', '3', 0x0a}
	expectedResponseHeader := []byte{0xff, 0xff, 0xff, 0xff, 'n', '\\'}

	response, err := client.Request(
		"qw.foppa.dk:27502",
		statusPacket,
		expectedResponseHeader,
	)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() *Client

func NewWithConfig

func NewWithConfig(config Config) *Client
Example
package main

import (
	"fmt"

	"github.com/vikpe/udpclient"
)

func main() {
	config := udpclient.Config{
		BufferSize:  256,
		Retries:     0,
		TimeoutInMs: 800,
	}
	client := udpclient.NewWithConfig(config)

	fmt.Print(client.GetConfig())
}

func (Client) GetConfig added in v0.1.2

func (c Client) GetConfig() Config

func (Client) SendCommand added in v0.1.2

func (c Client) SendCommand(address string, command Command) ([]byte, error)

func (Client) SendPacket added in v0.1.2

func (c Client) SendPacket(address string, packet []byte) ([]byte, error)
Example
package main

import (
	"fmt"

	"github.com/vikpe/udpclient"
)

func main() {
	client := udpclient.New()
	statusPacket := []byte{0xff, 0xff, 0xff, 0xff, 's', 't', 'a', 't', 'u', 's', ' ', '2', '3', 0x0a}

	response, err := client.SendPacket(
		"qw.foppa.dk:27502",
		statusPacket,
	)

	fmt.Println(response, err)
}

type Command added in v0.1.2

type Command struct {
	RequestPacket  []byte
	ResponseHeader []byte
}

type Config

type Config struct {
	BufferSize  uint16
	Retries     uint8
	TimeoutInMs uint16
}

type Sender added in v0.1.2

type Sender interface {
	SendCommand(address string, command Command) ([]byte, error)
	SendPacket(address string, packet []byte) ([]byte, error)
	GetConfig() Config
}

Jump to

Keyboard shortcuts

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