jsonsocket

package module
v0.0.0-...-7b3e3c8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 11 Imported by: 0

README

jsonsocket

go package for socket comms via json

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SocketClient

type SocketClient struct {
	ServerAddr string
	UseTLS     bool
	// contains filtered or unexported fields
}

SocketClient represents a client connection to the server.

func (*SocketClient) Await

func (sc *SocketClient) Await() ([]interface{}, error)

Await waits for data from the server.

func (*SocketClient) BroadcastToGroup

func (sc *SocketClient) BroadcastToGroup(groupID string, data interface{}) error

BroadcastToGroup sends a message to all clients in the specified group.

func (*SocketClient) Close

func (sc *SocketClient) Close()

Close closes the client connection.

func (*SocketClient) Connect

func (sc *SocketClient) Connect() error

Connect establishes a connection to the server.

func (*SocketClient) GetGroups

func (sc *SocketClient) GetGroups() []string

GetGroups returns the list of groups the client has joined.

func (*SocketClient) JoinGroup

func (sc *SocketClient) JoinGroup(groupID string) error

JoinGroup subscribes the client to a group.

func (*SocketClient) LeaveGroup

func (sc *SocketClient) LeaveGroup(groupID string) error

LeaveGroup unsubscribes the client from a group.

func (*SocketClient) Send

func (sc *SocketClient) Send(data []interface{}) error

Send sends data to the server.

type SocketGroup

type SocketGroup struct {
	Id      string                    // Id to map specific group.
	Clients map[string]*socketProcess // Stores all the clients listening to the group.
	Sync    sync.RWMutex              // Sync read and write to support multithreading.
}

SocketGroup represents a communication channel with its clients and synchronization mechanism.

type SocketMessage

type SocketMessage struct {
	Flag    enums.SocketFlag `json:"flag"`    // Flag indicates the type of message.
	Payload interface{}      `json:"payload"` // Payload contains the actual data.
	Group   string           `json:"group"`   // Channel sends payload across clients subscribed to it.
}

SocketMessage represents the structure of the JSON message used for communication.

type SocketServer

type SocketServer struct {
	Name      string
	Port      uint16
	EnableTLS bool
	CertPath  string
	KeyPath   string
	// contains filtered or unexported fields
}

func (*SocketServer) Bind

func (ss *SocketServer) Bind() string

Bind listen to new connections and if succeed return the client id.

func (*SocketServer) Broadcast

func (ss *SocketServer) Broadcast(groupId string, data []interface{})

func (*SocketServer) Close

func (ss *SocketServer) Close(ProcessID string)

func (*SocketServer) Listen

func (ss *SocketServer) Listen(clientId string) ([]interface{}, error)

Listen returns data from a specific client.

func (*SocketServer) Response

func (ss *SocketServer) Response(ProcessID string, data []interface{}) error

func (*SocketServer) Start

func (ss *SocketServer) Start() error

REFACTOR THIS

Directories

Path Synopsis
test

Jump to

Keyboard shortcuts

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