luasocket

Installing Lua socket library

纵然是瞬间 提交于 2019-12-10 03:49:06
问题 Either I'm overtired or blind. I want to learn networking with Lua and therefore I have to install the socket lib, so I can require it easily, but I don't know, which files I should "require". The example says: local socket = require("socket") but as I said, I don't know which files I should include, if I use socket.lua it doesn't work and I get: No files found . I got the lib from here: Lua socket download Or, is there another way to install the socket lib? 回答1: When you load a module with

quick-cocos2d-x 中的 socket 技术选择:LuaSocket 和 WebSocket

送分小仙女□ 提交于 2019-12-09 13:37:39
在 quick-cocos2d-x 中,默认集成了 LuaSocket 和 WebSocket 两个 Socket 库。那么,在开发需要长连接的手机游戏时,应该选择哪个库呢?下面从几个方面进行比较: 跨平台; 易用性; 性能; 流量; 灵活性; 二进制编码; 服务器实现。 一、跨平台 WebSocket 是跨平台的,其导出到lua的代码位于[quick]/lib/cocos2d-x/scripting/lua/cocos2dx_support/Lua_web_socket.cpp。 LuaSocket 也是跨平台的,其导出到lua的代码位于[quick]/lib/cocos2d-x/scripting/lua/lua_extensions/lua_extensions.c。quick 中集成的 LuaSocket 是 2.1RC 版本。 二、易用性 [quick]/samples/websockets 是quick提供的一个WebSocket范例。[quick]/samples/cocos2dx_luatest/scripts/ExtensionTest/WebProxyTest.lua也是一个范例。WebSocket 库封装了一些基本的事件支持 open/message/close/error ,在使用的时候比较方便。 WebSocket 天生就是非阻塞的。 在 quick 中

How can a LuaSocket server handle several requests simultaneously?

我们两清 提交于 2019-12-08 04:43:02
问题 The problem is the inability of my Lua server to accept multiple request simultaneously. I attempted to make each client message be processed in its on coroutine, but this seems to have failed. while true do local client = server:accept() coroutine.resume(coroutine.create( function() GiveMessage( client ) end ) ) end This code seems to not actually accept more than one client message at the same time. What is wrong with this method? Thank you for helping. 回答1: You will not be able to create

How do i use socket.select?

安稳与你 提交于 2019-12-08 01:54:24
问题 I need some help using socket "select" function. My server code is like this: while true do for _,server in pairs(servers) do local client = server:accept() client:settimeout(5) local line, err = client:receive() if not err then client:send(line .. "_SERVER_SIDE\n") else client:Send("___ERRORPC"..err) end client:close() end end But now i want to use the select function instead of make a forever loop like this. Reading this: http://w3.impa.br/~diego/software/luasocket/socket.html I know that i

In Luasocket, under which conditions can an accept call block even after select tells it is safe to read?

无人久伴 提交于 2019-12-07 15:08:20
问题 The Luasocket select function is supposed to tell when a socket can be read without blocking. It apparently can also be used to tell when a server socket is ready to accept a new connection however the documentation gives the following warning: Another important note: calling select with a server socket in the receive parameter before a call to accept does not guarantee accept will return immediately. Use the settimeout method or accept might block forever. Under what circumstances can accept

How could I embedded socket in Lua internally, just like oslib, debuglib?

淺唱寂寞╮ 提交于 2019-12-07 07:16:36
问题 I want to implement the function like embedding the socket function in my Lua build. So I don't need to copy socket.core.dll any more (just for fun). I search the maillist, and see some guys discuss the topic, http://lua-users.org/lists/lua-l/2005-10/msg00269.html But I have question for the details steps, who could give me a detailed steps for changing the lua and luasocket code to make them work together (not with dll method). I tried these steps in windows xp with VC2008: 1) copy luasocket

lua http socket timeout

删除回忆录丶 提交于 2019-12-07 01:40:41
问题 The LuaSocket HTTP module documentation says that a timeout can be set on a HTTP connection: The following constants can be set to control the default behavior of the HTTP module: PORT: default port used for connections; PROXY: default proxy used for connections; TIMEOUT: sets the timeout for all I/O operations; USERAGENT: default user agent reported to server. http://w3.impa.br/~diego/software/luasocket/http.htm How do I set these constants in a lua script? 回答1: You can do this to set a

How can a LuaSocket server handle several requests simultaneously?

走远了吗. 提交于 2019-12-06 21:27:38
The problem is the inability of my Lua server to accept multiple request simultaneously. I attempted to make each client message be processed in its on coroutine, but this seems to have failed. while true do local client = server:accept() coroutine.resume(coroutine.create( function() GiveMessage( client ) end ) ) end This code seems to not actually accept more than one client message at the same time. What is wrong with this method? Thank you for helping. You will not be able to create true simultaneous handling with coroutines only — coroutines are for cooperative multitasking. Only one

How do i use socket.select?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 09:29:54
I need some help using socket "select" function. My server code is like this: while true do for _,server in pairs(servers) do local client = server:accept() client:settimeout(5) local line, err = client:receive() if not err then client:send(line .. "_SERVER_SIDE\n") else client:Send("___ERRORPC"..err) end client:close() end end But now i want to use the select function instead of make a forever loop like this. Reading this: http://w3.impa.br/~diego/software/luasocket/socket.html I know that i can use something simmilar than: socket.select(servers, nil, 5) But i don´t know how i can use this on

How to download a file in Lua, but write to a local file as it works

南楼画角 提交于 2019-12-06 02:13:36
问题 I'm trying to make an updater so when my Lua application is out-of-date it will use LuaSocket to download the newer .exe file (which can run my Lua code). Inside this updater, I want it to show how much has been downloaded so far. However, with the following HTTP request, it blocks the application until downloaded fully: local b, c, h = http.request("https://www.example.com/Download/Example.exe?from="..Game.Version) I am using threads to download it, however I still cannot write to the file