You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

socket.js 391B

1234567891011121314151617181920
  1. socket = null;
  2. function getAddress() {
  3. var loc = window.location;
  4. var uri = loc.protocol === "https:" ? "wss:" : "ws:";
  5. uri += "//" + loc.host + "/ws";
  6. return uri;
  7. }
  8. function connect() {
  9. socket = new WebSocket(getAddress());
  10. socket.onmessage = function(event) {
  11. console.log(event.data);
  12. }
  13. }
  14. function send(data) {
  15. socket.send(JSON.stringify(data));
  16. }