From: Armin Roehrl Date: 2001-11-02T08:08:20+09:00 Subject: [ruby-talk:24125] Re: socket On Thursday 01 November 2001 23:59, you wrote: > Hi > > Has anyone a little code-snippet showing how i can make a > communication between a ruby-server and an rubyclient over tcp/ip? --server require 'socket' port=2006 server=TCPServer.new('localhost',port) while(session=server.accept)do session.print "Hallo" session.close end --client require 'socket' port, host = 2006, 'localhost' t=TCPSocket.new('localhost', port) p t.gets t.close or.. do it in one single ruby prg. require 'socket' class IPSocket def portInfo(out = STDOUT) out.puts "local: #{addr[1]}\n" + "remote: #{peeraddr[1]}" end end serverSocket = TCPServer.new('localhost', 9876) server = Thread.start { while (clientSocket = serverSocket.accept) clientSocket.portInfo puts "Anfrage: #{clientSocket.gets}" clientSocket.puts "Sie rufen au�erhalb der " + "Gesch�ftszeiten an ..." end } clientSocket = TCPSocket.new('localhost', 9876) clientSocket.portInfo clientSocket.puts "Hallo?" puts "Antwort: #{clientSocket.gets}" > > thx Frank -- Armin. ----------------------------------------------- Armin Roehrl, http://www.approximity.com "The best way to predict the future is to invent it." --Alan Kay