传输端点未连接@ io_fillbuf-fd:7(Errno :: ENOTCONN)

时间:2018-11-01 22:06:29

标签: ruby sockets

我正在尝试使用Ruby套接字编写聊天程序。当我运行客户端程序时,并检查服务器端;我收到此错误:Transport endpoint is not connected@io_fillbuf - fd:7 (Errno::ENOTCONN)。为什么我不断收到此错误,并且有更好的方法来做到这一点?

服务器:

require 'socket'

host = 'localhost'
port = 10000

s = TCPServer.new(host, port)

s.accept()

while msg = s.gets
    puts "Enter a message: "
    input = gets.chomp
    if msg
        puts "Received: #{msg}"
    else
        sleep
    end
end

客户:

require 'socket'

host = 'localhost'
port = 10000


s = TCPSocket.new(host, port)


puts "Established a connection!"

msg = s.gets()

if msg
    puts msg
else
    sleep
    end

0 个答案:

没有答案