• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天字一號

            泠泠七弦上 靜聽松風(fēng)寒 古調(diào)雖自愛 今人多不彈

               :: 首頁 :: 聯(lián)系 ::  :: 管理
              4 Posts :: 0 Stories :: 3 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團(tuán)隊(duì)

            最新評論

            閱讀排行榜

            由于項(xiàng)目要換成全Lua的,所以趁這個機(jī)會研究了下LuaSocket和Lua Loop
            Lua Loop: http://loop.luaforge.net/
            LuaSocket: http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/
            感覺用這個寫個簡單的聊天服務(wù)器,或者寫個文字Mud的網(wǎng)絡(luò)小游戲挺方便的,而且上手容易,適合一些策劃做些自己想法的東西。Lua Loop我就不做介紹了,上面網(wǎng)站例子有很多。下面兩段便是用Lua寫的個服務(wù)器和客戶端的示例代碼:
            運(yùn)行很簡單,只要將LuaSocket放在下面代碼說在的路徑,然后用lua5.0運(yùn)行。

             1 -- server端Lua代碼
             2 
             3 socket = require("socket");
             4 host = host or "localhost";
             5 port = port or "8383";
             6 server = assert(socket.bind(host, port, 1000))
             7 server:settimeout( 0 )
             8 
             9 local client = {}
            10 print("server: waiting for client connection")
            11 local clientcount    = 0
            12 while 1 do
            13     control                = server:accept()
            14     
            15     if control ~= nil then
            16         client[control] = control 
            17         clientcount        = clientcount + 1    
            18         print( "有新客戶端連入鏈接總數(shù)為:" .. clientcount .. "\n" )
            19     end
            20     
            21 
            22     for user in pairs( client ) do
            23         command            =  user:receive();
            24         if command ~= nil then 
            25             print( command )    
            26         end
            27     end
            28     
            29 end

             1 -- Client端Lua代碼
             2 local MaxLink     = 220
             3 local socket    = require("socket")
             4 local c = {}
             5 
             6 host = host or "localhost"
             7 port = port or 8383
             8 if arg then
             9     host = arg[1] or host
            10     port = arg[2] or port
            11 end
            12 print("Attempting connection to host '" ..host.. "' and port " ..port.. "")
            13 for i = 1, MaxLink do
            14     c[i] = assert(socket.connect(host, port))
            15     c[i]:settimeout( 0 )
            16 end
            17 
            18 print("Connected! Please type stuff (empty line to stop):")
            19 = io.read()
            20 for i = 1, MaxLink do
            21     assert( c[i]:send(l .. "\n") )
            22     assert( c[i]:send("test" .. i .. "\n") ) 
            23     print( "test" .. i .. "\n" )
            24 end
            25 
            26 while 1 do    
            27     for i = 1, MaxLink do
            28         command = c[i]:receive()
            29         if command ~= nil then 
            30             print(command)
            31         end
            32     end
            33 end
            34 
            posted on 2009-03-23 20:12 Wizard 閱讀(2988) 評論(1)  編輯 收藏 引用

            Feedback

            # re: 用Lua寫個輕量級服務(wù)器 2009-04-26 01:05 shongbee2
            先膜拜一下!然后再看。呵呵。  回復(fù)  更多評論
              


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久亚洲sm情趣捆绑调教| 色偷偷88欧美精品久久久| 久久人人爽人人人人爽AV| 久久精品国产免费一区| 一本一本久久aa综合精品| 亚州日韩精品专区久久久| 国产一区二区三精品久久久无广告| 浪潮AV色综合久久天堂| 久久人人爽人人爽人人片av麻烦| 久久久久综合国产欧美一区二区| 亚洲天堂久久精品| 精品久久一区二区三区| 久久精品99久久香蕉国产色戒| 亚洲精品乱码久久久久久按摩| 亚洲午夜久久久影院| 欧美噜噜久久久XXX| 97久久国产露脸精品国产| 久久天天躁夜夜躁狠狠| 精品久久久久久久国产潘金莲| 亚洲а∨天堂久久精品9966| 久久久久国色AV免费看图片| 一本大道久久香蕉成人网| 久久笫一福利免费导航| 一本一本久久A久久综合精品| 久久精品中文无码资源站| 国产99久久精品一区二区| 女人香蕉久久**毛片精品| 亚洲精品高清国产一久久| 欧美大战日韩91综合一区婷婷久久青草 | 久久精品人人做人人爽电影蜜月 | 久久精品国产99久久久古代| 久久久久波多野结衣高潮| av色综合久久天堂av色综合在| 久久久久亚洲AV成人片| 狠狠狠色丁香婷婷综合久久五月| 91久久香蕉国产熟女线看| 日本久久中文字幕| 伊人久久大香线蕉综合Av| 99久久精品费精品国产| 久久综合五月丁香久久激情| 亚洲日韩中文无码久久|