udpclient

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 5 Imported by: 8

README

UDP Client Go Reference Test codecov Go Report Card

UDP client for Go

Example

Send a status 23 packet to a QuakeWorld server.

package main

import (
	"fmt"

	"github.com/vikpe/udpclient"
)

func main() {
	client := udpclient.New()
	packet := []byte{0xff, 0xff, 0xff, 0xff, 's', 't', 'a', 't', 'u', 's', ' ', '2', '3', 0x0a}
	address := "qw.foppa.dk:27502"
	response, err := client.SendPacket(address, packet)

	fmt.Println(response, err)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config Config
}

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.Config)
}

func (Client) SendCommand added in v0.1.2

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

import (
	"fmt"

	"github.com/vikpe/udpclient"
)

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

	response, err := client.SendCommand("qw.foppa.dk:27502", command)
	fmt.Println(response, err)
}

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  uint32
	Retries     uint8
	TimeoutInMs uint16
}

Jump to

Keyboard shortcuts

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