Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang websocket client [closed]

Tags:

websocket

go

I want to make client websocket connections to exertnal server each connection = goroutine and reader. I was looking informations on the internet but I found how to create server websocket tutorials. Can anyone be so kind and make a trivial example and walk me through. I am using standart golang libary https://golang.org/x/net/websocket.

I created some code but when I closed one connection program exited with EOF information. I won't post the code because it's probably bad duo to the fact it was my first try.

I know how to read/send message from websocket but I don't know how to create multiple connections.

Any informations, examples would be appreciate, thanks for reading

like image 622
user3398940 Avatar asked Nov 26 '15 00:11

user3398940


3 Answers

You can use the Gorilla WebSocket library

Here's an example of it's use as a client

like image 154
David Budworth Avatar answered Oct 27 '22 13:10

David Budworth


Golang official doc recommends to use gorilla for building websocket based application. Still the problem is, gorilla websocket is not event based. Applications need to handle concurrent read and write operations. Developers need to write custom goroutines for handling connect, disconnect and read events. I think it is better to have a library handling everything for you. So, I decided to write down my own client implementation - gowebsocket on top of gorilla. You can find more detailed explaination here Getting started with websocket client in go

like image 25
Sachin Shinde Avatar answered Oct 27 '22 12:10

Sachin Shinde


You can check the comparison given on this link.

https://yalantis.com/uploads/ckeditor/pictures/4265/websocket-libraries.png

Article suggests to go for Gobwas(https://github.com/gobwas/ws). Its best performance wise and offers all the required features needed for websockets related applications.

like image 20
Mahendra Bagul Avatar answered Oct 27 '22 12:10

Mahendra Bagul