Skip to content

FES 开启websocket服务

0xcc edited this page May 9, 2018 · 1 revision

1.使用WebSocket监听端口9999

-- 主入口函数。从这里开始lua逻辑
function ServiceInit()
    
    print(" =========FES Main Start============ ");
    
    -- 前端服务器开启监听端口   
    -- 服务名字 : "ClientService"
    -- 使用ws   : websocket协议
    -- 监听端口 :9999
    
    ClientService:Init( "ClientService", "ws" );
    ClientService:Listen( 9999 );

end

2.使用WebSocketSsl监听端口9999

function ServiceInit()
    
    print(" =========FES Main Start============ ");
    
    -- 前端服务器开启监听端口   
    -- 服务名字 : "ClientService"
    -- 使用wss  : websocket协议,使用ssl加密信道
    -- 监听端口 :9999
    
    ClientService:Init( "ClientService", "wss" );
    
    -- 加载SSL证书
    local CrtPath = Misc.GetBasePath() .. "/script/DataTable/ssl/";
    ClientService:LoadSslCA(CrtPath.."1_root_bundle.crt");
    ClientService:LoadSslCrt(CrtPath.."2_ssl.com.crt");
    ClientService:LoadSslPrivateKey(CrtPath.."3_ssl.com.key");
    
    ClientService:Listen( 9999 );

end
Clone this wiki locally