Simplifies calling UDPIPE, by serializing command names and its arguments, and sending it to the server. It also wraps the server responses, calling callbacks function with unserialized arguments. It uses http://www-users.rwth-aachen.de
Warning: it is still a work-in-progress, yet it seems to be already useful. For now it is used only for the client side.
Note: you should use the instance of UDPIPE (created my UDPIPE()), not the instance of subclassed class. As this is the proxy object, it overrides the __index metamethod, so OO will not work.
This should simplify writing client side code. But it requires some changes on the server side, notably the data should be serialized using json as “command=<JSON Serialized arguments>”
UDPIPE=require 'UDPIPE' UDPROXY=require 'UDPROXY' conn=UDPIPE() conn:connect('127.0.0.1', 1110) Logic=UDPROXY(conn) function Logic:onReply(M) print('Reply count:'..M.counter..' content:'..M.msg) end function conn:onConnect() Logic:login('player1', 'secretpasswd') Logic:getGameState() end while true do Logic:update() end
It is just a simple echo server.
UDPIPE=require 'UDPIPE' json=require 'dkjson' server=UDPIPE() host, port='127.0.0.1', 1110 server:start(port, host) function server:onNewMessage(msg, sock) counter=(counter or 0)+1 self:send('Reply='..json.encode({msg=msg, counter=counter}), sock) end while true do server:step() end