https://github.com/sauldoescode/craftsocket
small wrapper around JavaScript's WebSocket API
https://github.com/sauldoescode/craftsocket
Last synced: 12 months ago
JSON representation
small wrapper around JavaScript's WebSocket API
- Host: GitHub
- URL: https://github.com/sauldoescode/craftsocket
- Owner: SaulDoesCode
- Created: 2015-11-01T16:16:13.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-11-01T16:26:17.000Z (over 10 years ago)
- Last Synced: 2025-01-04T20:35:21.795Z (about 1 year ago)
- Language: JavaScript
- Size: 191 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CraftSocket
small wrapper around JavaScript's WebSocket API
### Using CraftSocket
##### Make a new CraftSocket Object
``` javascript
var socket = new CraftSocket("ws://" + location.hostname + ":" + port + "/");
// The CraftSocket Object takes any ws:// or wss:// address
```
##### Send the Server a message
``` javascript
socket.send('Hello GoGo', res => console.log(res));
// First argument is the message you want to send
// Second argument is a callback function with the server response as a parameter
```
##### Recieve a message from the Server
``` javascript
socket.recieve(msg => console.log(msg));
// every time the server sends a message,
// the callback function will fire with the server's response as a parameter
```