Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby——为什么我的服务器停止工作_Ruby_Sockets_Lua_Coronasdk - Fatal编程技术网

Ruby——为什么我的服务器停止工作

Ruby——为什么我的服务器停止工作,ruby,sockets,lua,coronasdk,Ruby,Sockets,Lua,Coronasdk,我编写的应用程序使用Lua,并使用Ruby连接到服务器,但当应用程序启动时,它似乎停止工作。我不确定问题出在哪里,因为我是Ruby新手,但我曾经使用过Python,也有同样的问题 我很好奇Ruby是否有http协议要求?下面是我使用puts向客户端发送数据的代码 require "socket" class Server def initialize(ip,port) puts "Server Start!!" @server = TCPServer.op

我编写的应用程序使用Lua,并使用Ruby连接到服务器,但当应用程序启动时,它似乎停止工作。我不确定问题出在哪里,因为我是Ruby新手,但我曾经使用过Python,也有同样的问题

我很好奇Ruby是否有http协议要求?下面是我使用puts向客户端发送数据的代码

require "socket"
class Server
    def initialize(ip,port)
        puts "Server Start!!"
        @server = TCPServer.open(ip,port)
        @connections = Hash.new
        @rooms = Hash.new
        @clients = Hash.new
        @connections[:server] = @server
        @connections[:rooms] = @rooms
        @connections[:clients] = @clients
    end

    def run
        loop {
            Thread.start(@server.accept) do |client|
                puts "New client connected."
                nickname = client.gets.chomp.to_sym

                puts "#{nickname} #{client}"
                @connections[:clients][nickname] = client
                client.puts "Hi there"
                client.print "\n"
                client.close
            end
        }.join
    end
end

server = Server.new("127.0.0.1",8080)
server.run


在线程结束时,函数应该可以运行

仍然不能运行。我已经更新了帖子中的代码。这是你的意思吗?
client.print "\n
client.close