https://github.com/barokurniawan/websocket
simple websocket implementation
https://github.com/barokurniawan/websocket
golang websocket
Last synced: 5 months ago
JSON representation
simple websocket implementation
- Host: GitHub
- URL: https://github.com/barokurniawan/websocket
- Owner: barokurniawan
- Created: 2019-10-15T07:34:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-08T23:48:39.000Z (almost 6 years ago)
- Last Synced: 2024-06-19T04:27:04.808Z (about 2 years ago)
- Topics: golang, websocket
- Language: Go
- Homepage:
- Size: 126 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# websocket
Saya menggunakan service ini untuk melakukan update pada sebuah halaman berdasarkan interaksi dihalaman lain, ini lebih efisien dari pada menggunakan long polling ajax.
## INSTALASI
1. clone repository ini `git clone git@github.com:barokurniawan/websocket.git`
2. install [go-dep](https://github.com/golang/dep)
3. jalankan `dep ensure` untuk menginstall dependency
## Menggunakan Docker
- `docker-compose up --build`
## RUN
```
const SOCKET_CHANNEL = "PITSTOP_FIRST";
window.customSocket = {};
window.customSocket.init = function () {
if (!(window.WebSocket)) {
console.log("Browser doesnot support websocket");
return
}
window.customSocket = new WebSocket("ws://localhost:3001/socket?channel=" + SOCKET_CHANNEL)
window.customSocket.onopen = function () {
console.log("Connect to websocket, send and receive on chanel " + SOCKET_CHANNEL);
}
window.customSocket.onmessage = function (event) {
console.log("incoming...");
console.log(event);
}
window.customSocket.onclose = function () {
console.log("Disconnected from websocket");
}
}
window.customSocket.doSendMessage = function () {
window.customSocket.send(JSON.stringify({
Channel: SOCKET_CHANNEL,
Message: "CHANGE"
}));
}
window.onload = window.customSocket.init
```
```
window.customSocket.send(JSON.stringify({
Channel: "PITSTOP_FIRST", // or MINE
Message: "CHANGE"
}));
```
### Thanks
[Noval Agung](https://github.com/novalagung/dasarpemrogramangolang) - tutorial web socket