123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- --[[
- Descripttion:
- version:
- Author: Neo,Huang
- Date: 2022-07-06 10:42:14
- LastEditors: Neo,Huang
- LastEditTime: 2022-07-06 11:27:01
- --]]
- require "skynet.manager"
- local skynet = require "skynet"
- local socket = require "skynet.socket"
- local nodes = require("nodes")
- local agentList = {}
- skynet.start(
- function()
- local nodeName = skynet.getenv("nodeName")
- local ip = nodes[nodeName].ip
- local port = nodes[nodeName].port
- local agentCount = nodes[nodeName].agentCount
- local bodyLimit = nodes[nodeName].bodyLimit or 8192
- log.info("node[%s] ip[%s] port[%s]", nodeName, ip, port)
- -- 创建代理服务
- for i = 1, agentCount do
- local handle = skynet.newservice("srvHttpAgent", bodyLimit)
- table.insert(agentList, handle)
- end
- local balance = 1
- local listenId = socket.listen(ip, port, 128)
- skynet.error(string.format("%s server listen %s:%s", nodeName, ip, port))
- socket.start(
- listenId,
- function(id, addr)
- local cip, cport = string.match(addr, "([^:]+):?(%d*)$")
- skynet.send(agentList[balance], "lua", "http", id, cip)
- balance = balance + 1
- if balance > #agentList then
- balance = 1
- end
- end
- )
- skynet.register(".http_server")
- end
- )
|