jjh-ruby-talk / vieorhythms.com wrote in message news:<87oeuzhr7h.fsf / planchet.hinegardner.org>... > >>>>> "BCoish" == BCoish <BCoish / Dymaxion.ca> writes: > > BCoish> I've run into a problem that I'm hoping is not unique. I am > BCoish> learning TCP/IP programming in Ruby and the following code > BCoish> generates a strange result: > > The original code doesn't work on a Linux machine either. Here's > slightly altered code that probably will do what you want. > > [jeremyhi@rapier ruby]$ cat client.rb > # CLIENT.RB > # ========= > require 'socket' > s=TCPSocket.new("localhost", ARGV[0]) > s.write("test\n") > puts s.gets > s.close() > [jeremyhi@rapier ruby]$ > > > Change server.rb to only read from the client 1 time. > > [jeremyhi@rapier ruby]$ cat server.rb > # SERVER.RB > # ========= > require "socket" > gs = TCPserver.open(0) > printf("server is on port %d\n", gs.addr[1]) > s = gs.accept > line = s.gets > puts line > s.write(line.upcase) > s.close > > BCoish> The preceeding code is used to run a server that accepts a > BCoish> single client. The client sends the server a string, the server > BCoish> reads and converts the string to uppercase and then sends it > BCoish> back to the client. > > The server as originally written reads from the client twice, once for > each 'gets'. Since the client is only writing once to the server this > is probably the underlying issue. > > BCoish> That's how it's supposed to work and on the PC it does work. > BCoish> However, on OpenVMS the client requires two, consecutive reads > BCoish> in order to get the uppercased value from the server (i.e. first > BCoish> read returns the original string "test"; second read returns the > BCoish> modified string sent back by the server "TEST"). This leads me > BCoish> to believe it's an internal buffer problem. Before I speculate > BCoish> further I wanted to ask if anyone has come across this before > BCoish> and what may be the cause of it. > > enjoy, > > -jeremy First, thanks for the speedy response! Second, I modified the source per your suggestions, but without success. This is now the code I'm running: # Client ######## require 'socket' s=TCPSocket.new("localhost", ARGV[0]) s.write("test\n") puts s.gets # puts s.gets s.close # Server ######## require 'socket' gs = TCPServer.open(0) printf("server is on port %d\n", gs.addr[1]) s=gs.accept s.write(s.gets.upcase) s.close Even if I break s.gets.upcase down into it's constituent parts the problem persists. Any other ideas? (I'm fresh out) :) Perhaps something in the actual implimentation is the same everywhere else except for OpenVMS. Hmm, wouldn't be the first time, but it is a pain. :) Thanks, Brad