Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang
Server and client using STOMP and WebSocket in Go. WebSocket with notifications for logged-in and logged-out users with log server, implementing JWT authentication and STOMP authentication.
https://github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang
golang jwt-auth jwt-authentication stomp stomp-client stomp-server websocket websocket-client websocket-server
Last synced: about 2 months ago
JSON representation
Server and client using STOMP and WebSocket in Go. WebSocket with notifications for logged-in and logged-out users with log server, implementing JWT authentication and STOMP authentication.
- Host: GitHub
- URL: https://github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang
- Owner: rafaelsouzaribeiro
- Created: 2023-12-17T17:16:11.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-29T23:09:42.000Z (7 months ago)
- Last Synced: 2024-07-17T06:25:56.645Z (6 months ago)
- Topics: golang, jwt-auth, jwt-authentication, stomp, stomp-client, stomp-server, websocket, websocket-client, websocket-server
- Language: Go
- Homepage:
- Size: 79.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Server and client using STOMP and WebSocket in Go. WebSocket with notifications for logged-in and logged-out users with log server, implementing JWT authentication and STOMP authentication.
For web chat access, visit the repository.For multiple messages on the websocket, the username is linked to a connection, so whenever you send more than one message to the username, you need to use client.Connect()
```go
package mainimport (
"fmt"
"time""github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang/internal/infra/web/websocket/client"
"github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang/internal/usecase/dto"
)func main() {
channel := make(chan dto.Payload)client3 := client.NewClient("localhost", "ws", 8080)
client3.Channel = channelclient4 := client.NewClient("localhost", "ws", 8080)
client4.Channel = channelgo func() {
client3.Connect()
go client3.Listen()
for range time.Tick(time.Second * 1) {
client3.Send("Client 3", "Hello 3")
}
}()go func() {
client4.Connect()
go client4.Listen()
for range time.Tick(time.Second * 1) {
client4.Send("Client 4", "Hello 4")
}
}()for msg := range channel {
fmt.Printf("%s: %s\n", msg.Username, msg.Message)
}
}```
send messages to a single username```go
package mainimport (
"fmt""github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang/internal/infra/web/websocket/client"
"github.com/rafaelsouzaribeiro/server-and-client-using-stomp-and-websocket-in-golang/internal/usecase/dto"
)func main() {
channel := make(chan dto.Payload)
go func() {
client := client.NewClient("localhost", "ws", 8080)
defer client.Conn.Close()
client.Connect()
client.ClientWebsocket("Client 1", "Hello 1", channel)
}()for obj := range channel {
fmt.Printf("%s: %s\n", obj.Username, obj.Message)
}close(channel)
}
```