lipp / lipp/lua-websockets

copas looping issue while connecting the server

Open
#104 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
419
Forks
117
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Lua 5.1 script on OpenWrt and inspect how client:receive interacts with copas.loop after the initial send and receive operations. The issue is resolved when the client continues listening and can exchange messages without stopping or timing out.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.