From: chris guenther Date: 2005-04-10T18:19:39+09:00 Subject: weird delay of UDP server (seems to be thread-scheduling issue) Hi, the UDP client/server progam below does not work as expected. Given one input line ('df' see below) the server-thread does not (YET) receive the UDP packet, although the client thread had sent it already. ONLY after entering another bunch of empty lines (just hitting ) the receiver thread suddenly receives the packet. It seems to me that the receiver thread is not scheduled at the time I expect it to be scheduled (right after sending). Can anyone throw some light on this issue ?? TIA, Chris #--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-= #!/usr/bin/env ruby require 'socket' require 'time' STDOUT.sync=true $port = 4321 def now; Time.new.strftime('%H:%M:%S') ;end sThread = Thread.start do puts "server : bound port #{$port} at #{now}\n" server = UDPSocket.open server.bind(nil, $port) loop { puts "#{server.recvfrom(1024)[0]}\treceived at #{now}" } end sock = UDPSocket.open sock.connect('localhost', $port) loop { print "--> " case line = readline.chomp when /^q/ exit 0 else if line.length>0 ### Dont send EMPTY LINES payload="'#{line}'\tsent at #{now}" sock.send(payload, 0) puts "sent ::\t#{payload}" end end } #--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-= ############ trace of execution ############ # ruby -v -w udp_test.rb ruby 1.8.2 (2004-12-25) [i386-mswin32] server : bound port 4321 at 11:01:02 --> df sent :: 'df' sent at 11:01:05 --> --> --> --> --> --> --> --> --> --> 'df' sent at 11:01:05 received at 11:01:09