udp

package
v2.20.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 4 Imported by: 0

README

UDP

Server

package main

import (
	"log"

	"github.com/go-kratos/kratos/v2"

	"github.com/go-kratos-ecosystem/components/v2/udp"
)

func main() {
	err := kratos.New(
		kratos.Server(
			udp.NewServer(":12190", udp.WithHandler(func(msg *udp.Message) {
				log.Printf("receive message: %s", msg.Body)
			}), udp.WithRecoveryHandler(func(msg *udp.Message, err any) {
				log.Println(err)
			}), udp.WithReadChanSize(10240)),
		),
	).Run()

	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	Conn net.PacketConn
	Addr net.Addr
	Body []byte
}

type Option

type Option func(*Server)

func WithBufSize

func WithBufSize(bufSize int) Option

func WithHandler

func WithHandler(handler func(message *Message)) Option

func WithReadChanSize

func WithReadChanSize(readChanSize int) Option

func WithRecoveryHandler

func WithRecoveryHandler(handler func(message *Message, err any)) Option

type Server

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

func NewServer

func NewServer(address string, opts ...Option) *Server

func (*Server) Start

func (s *Server) Start(_ context.Context) (err error)

func (*Server) Stop

func (s *Server) Stop(_ context.Context) error

Jump to

Keyboard shortcuts

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