1

I'm trying to use UnixSocket in my Ruby scripts in Order to let multiple processes communicate with each other.

But i don't understand why i i can send only one message to the listening process. Stipped to the basics i have:

Server

require 'socket'
server = UNIXServer.open('/tmp/scanlcd_test.sock')
while true do
    client = server.accept
    puts "I got: " + client.readline
end

server.close

Client:

require 'socket'
client = UNIXSocket.open('/tmp/scanlcd_test.sock')
client.puts "1"
sleep 9
client.puts "2"
client.puts "3"
client.puts "4"

The result is:

./server.rb
I got: 1

Thats it ... the last 3 puts are gone ... Whats wrong there?

Dakkar
  • 5,682
  • 5
  • 22
  • 28
  • 1
    dude, you gotta loop on the cient readline, as you're only reading one line and then blocking on the `server.accept` – Anya Shenanigans Feb 22 '13 at 21:30
  • Urghs. you are right. Is it right, that new `client.puts` to that socket are queued, until the recent client closes its connection? Is there a limitation, how many "messages" are queued to that single socket? – Dakkar Feb 23 '13 at 07:15
  • 1
    The messages from the client are queued for reading. The amount of messages that are queued is platform specific and may be tunable. See http://stackoverflow.com/questions/7865069/how-to-find-the-socket-buffer-size-of-linux for the linux answer. – Anya Shenanigans Feb 23 '13 at 09:29

0 Answers0