From: mr ra88it Date: 2005-12-21T06:02:56+09:00 Subject: Re: Difficulty opening a socket Thanks again, Bob et al. It works! I appreciate your help... On 12/20/05, Bob Showalter wrote: > mr ra88it wrote: > > Thanks, everyone. > > > > Like I said, I know nothing about sockets and realize now I probably > > should have asked this question elsewhere. > > It's fine. We just couldn't figure out what you're tying to do. > > > I wasn't trying to do anything except send data over some sockets with > > ruby. Just playing. > > You need to go ahead and write a simple server and a client. > > Here's a simple "echo" server, that reads lines from the client and > sends them back: > > require 'socket' > sock = TCPServer.new(7777) > while client = sock.accept > puts "Connection received from #{client.peeraddr.inspect}" > while s = client.gets > client.puts s > end > puts "Connection from #{client.peeraddr.inspect} terminated" > end > > Here's a client to test the server: > > require 'socket' > server = TCPSocket.new('localhost', 7777) > server.puts "Hello!" > puts "Server says: #{server.gets}" > server.close > > Start the server in one window. Then go to another window and run the > server. > > You can also exercise your server with telnet: > > telnet localhost 7777 > > Lines that you type will be echoed back by the server. (From telnet, you > close the connection by typing the telnet "escape" character, often ^], > and then typing "close") > >