thanks a lot...
I have solved it just by lua concatation.
suppose that my data type and data content are:
local dataType = x -- string data
local dataContent=y --binary bytearray data
so just we will try to send the data like this:
local sock = ngx.socket.tcp()
local ok, err = sock:connect("x.x.x.x","100")
if not ok then
ngx.log(ngx.ERR,"Failed to connect to minifier socket!")
return
end
local bytes, err = sock:send(dataType.. dataContent)
sock:settimeout(10000)
then we can receive it fron node and then we can retrieve both data (type and content) like:
var Buffer = require('buffer').Buffer;
var buf = new Buffer(data); // dataType.. dataContent
var datatype = buf.slice(0, 3).toString();
var dataContent = buf.slice(3, data.length);
On Tuesday, April 17, 2018 at 7:26:53 AM UTC+4:30, tokers wrote:
The data inside the array-like Lua table will be jointed together as a string.
On Tuesday, April 17, 2018 at 10:55:33 AM UTC+8, tokers wrote:
Hello!
The only structure type that the ngx.socket.tcp can send is the array-like Lua table. So you need to serialize your structure via lua-cjson, lua-cmsgpack and etc by yourself.