Skip to content

Lesion45/go-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Server

This server can be used as a template for your project that is based on a client-server architecture.

Explanation

The server application defines two types, Client and Hub. The server creates an instance of the Client type for each websocket connection. A Client acts as an intermediary between the websocket connection and a single instance of the Hub type. The Hub maintains a set of registered clients and broadcasts messages to the clients.

The application runs one goroutine for the Hub and two goroutines for each Client. The goroutines communicate with each other using channels. The Hub has channels for registering clients, unregistering clients and broadcasting messages. A Client has a buffered channel of outbound messages. One of the client's goroutines reads messages from this channel and writes the messages to the websocket. The other client goroutine reads messages from the websocket and sends them to the hub.

About

A WebSocket server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages