websocket

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: MIT Imports: 8 Imported by: 2

README

Websocket

GitHub Build Coverage Go Report Card GoDoc

Rust Web RCON Protocol implementation in Go.

Supported Games

  • Rust (add +rcon.web 1 to the args when starting the server)

Install

go get github.com/gorcon/websocket

See Changelog for release details.

Usage

package main

import (
	"log"
	"fmt"

	"github.com/gorcon/websocket"
)

func main() {
	conn, err := websocket.Dial("127.0.0.1:28016", "password")
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	response, err := conn.Execute("status")
	if err != nil {
		log.Fatal(err)
	}
	
	fmt.Println(response)	
}

Requirements

Go 1.15 or higher

Contribute

Contributions are more than welcome!

If you think that you have found a bug, create an issue and publish the minimum amount of code triggering the bug so it can be reproduced.

If you want to fix the bug then you can create a pull request. If possible, write a test that will cover this bug.

License

MIT License, see LICENSE

Documentation

Index

Constants

View Source
const (
	// DefaultDialTimeout provides default auth timeout to remote server.
	DefaultDialTimeout = 5 * time.Second

	// DefaultDeadline provides default deadline to tcp read/write operations.
	DefaultDeadline = 5 * time.Second

	// MaxCommandLen is an artificial restriction, but it will help in case of random
	// large queries.
	MaxCommandLen = 1000
)
View Source
const RandIdentifierLimit = 1000

Variables

View Source
var (
	// ErrAuthFailed is returned when the package id from authentication
	// response is -1.
	ErrAuthFailed = errors.New("authentication failed")

	// ErrCommandTooLong is returned when executed command length is bigger
	// than MaxCommandLen characters.
	ErrCommandTooLong = errors.New("command too long")

	// ErrCommandEmpty is returned when executed command length equal 0.
	ErrCommandEmpty = errors.New("command too small")
)
View Source
var DefaultSettings = Settings{
	// contains filtered or unexported fields
}

DefaultSettings provides default deadline settings to Conn.

Functions

This section is empty.

Types

type Conn

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

Conn represents a WebSocket connection.

func Dial

func Dial(address string, password string, options ...Option) (*Conn, error)

Dial creates a new authorized WebSocket dialer connection.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

func (*Conn) Execute

func (c *Conn) Execute(command string) (string, error)

Execute sends command string to execute to the remote server.

func (*Conn) LocalAddr added in v1.0.0

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns the local network address.

func (*Conn) RemoteAddr added in v1.0.0

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote network address.

type Message

type Message struct {
	// Message field is a string command to send to the server and response
	// message from RemoteServer.
	Message string `json:"Message"`

	// Identifier field is a 32-bit little endian integer chosen by the
	// client for each request. It may be set to any positive integer.
	// When the RemoteServer responds to the request, the response packet
	// will have the same Identifier as the original request.
	// It need not be unique, but if a unique packet id is assigned,
	// it can be used to match incoming responses to their corresponding requests.
	Identifier int `json:"Identifier"`

	// Type is the type of message that was sent or received.
	// Can take the following values: Generic, Log, Warning, Error.
	// When sending a request, you can leave it blank.
	Type string `json:"Type"`

	Stacktrace string `json:"stacktrace"`
}

Message is both requests and responses are sent as packets wia WebSocket. Their payload follows the following basic structure.

type Option

type Option func(s *Settings)

Option allows to inject settings to Settings.

func SetDeadline

func SetDeadline(timeout time.Duration) Option

SetDeadline injects read/write Timeout to Settings.

func SetDialTimeout

func SetDialTimeout(timeout time.Duration) Option

SetDialTimeout injects dial Timeout to Settings.

type Settings

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

Settings contains option to Conn.

Jump to

Keyboard shortcuts

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