main.lua 508 B

1234567891011121314151617181920212223242526272829303132
  1. local copas = require "copas"
  2. local socket = require "socket"
  3. local cjson = require "cjson"
  4. local WebSocketClient = require('websocket')
  5. local client = WebSocketClient.new({
  6. uri = "http://localhost:3000"
  7. })
  8. function myFunction()
  9. local testJSON = {
  10. id = 123,
  11. price = 0,
  12. name = 'Alex',
  13. volume = 0
  14. }
  15. -- print(type(testJSON) == 'table')
  16. client:send({
  17. command = 'orders',
  18. body = testJSON
  19. })
  20. end
  21. -- Sleep for 2 seconds (2000 ms)
  22. socket.sleep(5)
  23. myFunction()
  24. copas.loop()