Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. var data = JSON.stringify(
  2. {
  3. "method" : "users.log_in",
  4. "params" : {
  5. "login" : "login",
  6. "password" : "qwerty"
  7. },
  8.  
  9. });
  10.  
  11.  
  12. var WebSocket = require('ws');
  13.  
  14. var ws = new WebSocket('ws://<ip>:<port>/apis');
  15.  
  16.  
  17. ws.on('open', function open() {
  18. console.log('connected');
  19. ws.send(data, function ack(error) {
  20. console.log(error);
  21. });
  22. });
  23.  
  24. ws.on('message', function incoming(data) {
  25. console.log(data);
  26.  
  27. });
  28.  
  29.  
  30. var io = require('socket.io-client');
  31.  
  32. var socket = io('ws://<ip>:<port>', {'path': '/apis', 'transports': ['websocket']});
  33.  
  34. socket.on('connect_error', function(err){
  35. console.log('Connection Failed');
  36. console.log(err);
  37. });
  38. socket.on('connect', function(){
  39. console.log('Connected');
  40. });
  41. socket.on('disconnect', function () {
  42. console.log('Disconnected');
  43. });
  44. socket.send(data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement