clientServerConnect.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. var SERVER_ADDRESS = '127.0.0.1';
  2. var SERVER_PORT = 61613;
  3. var QUEUE = '/queue/thing';
  4. if (process.argv.length > 2) {
  5. if (process.argv[2]) {
  6. SERVER_PORT = process.argv[2];
  7. }
  8. } else {
  9. var stompServer = require('../lib/server').createStompServer(SERVER_PORT).listen();
  10. }
  11. var StompClient = require('../lib/client').StompClient;
  12. var stompClient = new StompClient(SERVER_ADDRESS, SERVER_PORT, '', '', '1.0');
  13. stompClient.connect(function() {
  14. stompClient.subscribe(QUEUE, function(data, headers){
  15. console.log('GOT A MESSAGE', data, headers);
  16. });
  17. setTimeout(function(){
  18. stompClient.publish(QUEUE, 'oh herrow!');
  19. }, 1000);
  20. setTimeout(function(){
  21. stompClient.publish(QUEUE, 'wonely...');
  22. }, 2000);
  23. setTimeout(function(){
  24. stompClient.publish(QUEUE, 'so wonely...');
  25. }, 3000);
  26. setTimeout(function(){
  27. stompClient.publish(QUEUE, 'so wonely, so wonely and bwue!');
  28. }, 4000);
  29. setTimeout(function(){
  30. stompClient.disconnect(function() {
  31. console.log('DISCONNECTED');
  32. });
  33. }, 5000);
  34. });