0
我想了解Socket类和我使用下面的例子来实现服务器样本如何远程登录地址?
local server = assert(socket.bind("*", 0))
-- find out which port the OS chose for us
local ip, port = server:getsockname()
-- print a message informing what's up
print("Please telnet to localhost on IP [" ..ip.. "] and port [" .. port .. "]")
print("After connecting, you have 10s to enter a line to be echoed")
-- loop forever waiting for clients
while true do
-- wait for a connection from any client
local client = server:accept()
-- make sure we don't block waiting for this client's line
client:settimeout(10)
-- receive the line
local line, err = client:receive()
-- if there was no error, send it back to the client
if not err then
client:send(line .. "\n")
end
-- done with client, close the object
client:close()
end
但现在的问题是,我怎么可以telnet例如地址本地主机:通过LUA 8080 ?
编辑: 我忘了说什么,我甚至不能在cmd上telnet。当我键入命令:
的telnet IP端口
它总是说“连接丢失”后,我发送消息。我究竟做错了什么?
我这样做了。实际上,当我输入telnet命令,它连接,但当我发送一条消息(例如“你好”),我的连接丢失,我的lua程序无法收到消息。我不知道为什么... – Crasher 2013-04-10 14:57:31
Telnet需要客户端和服务器。 – Zyerah 2013-04-10 16:02:59
我的客户端和服务器处于活动状态,但仍然收到相同的消息,不知道为什么... – Crasher 2013-04-10 16:50:47