mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
rewrite client demo by lua, remove old C version client demo
This commit is contained in:
35
examples/client.lua
Normal file
35
examples/client.lua
Normal file
@@ -0,0 +1,35 @@
|
||||
package.cpath = "luaclib/?.so"
|
||||
|
||||
local socket = require "clientsocket"
|
||||
local cjson = require "cjson"
|
||||
|
||||
local fd = socket.connect("127.0.0.1", 8888)
|
||||
|
||||
local last
|
||||
local result = {}
|
||||
|
||||
local function dispatch()
|
||||
while true do
|
||||
local status
|
||||
status, last = socket.recv(fd, last, result)
|
||||
if status == nil then
|
||||
error "Server closed"
|
||||
end
|
||||
if not status then
|
||||
break
|
||||
end
|
||||
for _, v in ipairs(result) do
|
||||
print(v)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
while true do
|
||||
dispatch()
|
||||
local cmd = socket.readline()
|
||||
if cmd then
|
||||
socket.send(fd, cmd)
|
||||
else
|
||||
socket.usleep(100)
|
||||
end
|
||||
end
|
||||
@@ -16,14 +16,13 @@ end
|
||||
local trace_cache = {}
|
||||
|
||||
skynet.trace_callback(function(handle, ti)
|
||||
print("TRACE",trace_cache[handle],ti)
|
||||
-- print("TRACE",trace_cache[handle],ti)
|
||||
trace_cache[handle] = nil
|
||||
end)
|
||||
|
||||
skynet.start(function()
|
||||
skynet.dispatch("text", function(session, address, message)
|
||||
trace_cache[skynet.trace()] = message
|
||||
print("simpledb",message, skynet.address(address), session)
|
||||
local cmd, key , value = string.match(message, "(%w+) (%w+) ?(.*)")
|
||||
local f = command[cmd]
|
||||
if f then
|
||||
|
||||
Reference in New Issue
Block a user