Skip to content

copas looping issue while connecting the server #104

Description

@pritammore

Hi,
I am new to lua programming and trying to implement Lua-websocket in openwrt as a client.
Was trying to use client copas library but the issue is the script is getting stopped listening server after executing once (i.e. connecting to server, receiving message, sending message). I want the script to always listen the server without any timeout or script halt.
Below is the script

local copas = require'copas'
local websocket = require'websocket'
local json = require('json')
local client = require 'websocket.client'.new()

local ok,err = client:connect('ws://192.168.1.250:8080')
if not ok then
print('could not connect',err)
end

local ap_mac = { command = 'subscribe', channel = 'test' }
local ok = client:send(json.encode(ap_mac))
if ok then
print('msg sent')
else
print('connection closed')
end

local message,opcode = client:receive()
if message then
print('msg',message,opcode)
else
print('connection closed')
end

local replymessage = { command = 'message', message = 'TEST' }
local ok = client:send(json.encode(replymessage))
if ok then
print('msg sent')
else
print('connection closed')
end

copas.loop()

Here copas.loop() is not working.

On openWrt I had installed lua 5.1
Any help would be appreciated.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions