• <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>

            天字一號(hào)

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

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

            常用鏈接

            留言簿(1)

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

            最新評(píng)論

            閱讀排行榜

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

            Feedback

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


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


            青青热久久国产久精品 | 久久久青草久久久青草| 久久精品国产99久久久| 亚洲国产精久久久久久久| 久久亚洲精品无码播放| 久久久久波多野结衣高潮| 久久久精品人妻一区二区三区蜜桃| 久久婷婷五月综合国产尤物app| 久久精品国产亚洲AV香蕉| 一本久久久久久久| 青青久久精品国产免费看| 天天爽天天狠久久久综合麻豆| 久久亚洲高清观看| 久久婷婷五月综合国产尤物app| 国产一区二区三区久久精品| 欧美国产成人久久精品| 久久婷婷五月综合国产尤物app| 国内精品久久久久久久亚洲| 狠狠综合久久AV一区二区三区| 99久久精品国产一区二区| 久久久久国产精品嫩草影院| 999久久久免费国产精品播放| 77777亚洲午夜久久多喷| 精品久久久久久国产牛牛app| 少妇高潮惨叫久久久久久| 久久国产成人午夜aⅴ影院 | 热re99久久精品国产99热| 亚洲精品乱码久久久久久按摩| 精品久久久久久久久久久久久久久| 无码国内精品久久综合88| 国产免费久久精品99久久| 久久久久亚洲av无码专区| 久久婷婷色综合一区二区| 久久久久亚洲AV综合波多野结衣 | 国产偷久久久精品专区 | 久久91精品久久91综合| 久久久久久亚洲AV无码专区| 久久久久人妻一区二区三区| 中文字幕无码av激情不卡久久| 久久久久亚洲AV成人网| 久久996热精品xxxx|