server.rb
require 'socket'
Socket.tcp_server_loop(6666) do |connection|
while data = connection.read(1024 * 16) do
if data == 'hello'
connection.write('hi hi hi hi hi')
end
end
connection.close
end
client.rb require 'socket' require 'io/console'
client = TCPSocket.new('localhost', 6666)
client.write('hello')
client.flush
# client.close_write
# client.close_write
# client.fdatasync
# client.fsync
data = client.read
puts data
# client.open
# client.write('hello')
# puts client.read
I want to reuse the socke, so I don't want to close it.
But if I don't send client.close_write , it not work, cann't read server data. if client.close_write the socket closed, and it will not write data to server any more.
I want to know how to tell EOF and don't close the socket? client.fdatasync => in `fdatasync': Operation not supported (Errno::ENOTSUP)
client.fsync => in `fsync': Operation not supported (Errno::ENOTSUP)
I thought the fdatasync and fsync maybe the method to tell EOF, but they not work.
c language has a method to do that: ssize_t send(int sockfd, const void *buff, size_t nbytes, int flags) the nbytes tell the server data size. there is no method like this in ruby.