Ruby——为什么我的服务器停止工作
我编写的应用程序使用Lua,并使用Ruby连接到服务器,但当应用程序启动时,它似乎停止工作。我不确定问题出在哪里,因为我是Ruby新手,但我曾经使用过Python,也有同样的问题 我很好奇Ruby是否有http协议要求?下面是我使用puts向客户端发送数据的代码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
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