udpclient

package module
v0.1.1 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

func New

func New() *defaultClient

func NewWithConfig

func NewWithConfig(config Config) *defaultClient
Example
package main

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

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

func Request added in v0.1.1

func Request(client UdpClient, address string, statusPacket []byte, expectedResponseHeader []byte) ([]byte, error)

Types

type Config

type Config struct {
	BufferSize  uint16
	Retries     uint8
	TimeoutInMs uint16
}

type UdpClient added in v0.1.1

type UdpClient interface {
	Request(address string, statusPacket []byte, expectedResponseHeader []byte) ([]byte, error)
	GetConfig() Config
}

Jump to

Keyboard shortcuts

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