我编写了我的应用程序,使用Lua并使用Ruby连接到我的服务器但是当应用程序启动时,它似乎停止工作。我不确定问题是什么,因为我是Ruby的新手,但我曾经使用过Python并遇到同样的问题Corona Simulator stop working after connecting to server
我很好奇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
答案 0 :(得分:0)
添加
client.print "\n
client.close
在线程函数结束时它应该可以工作