From: Brian Candler Date: 2009-01-26T00:48:20+09:00 Subject: Re: How to receive data using socket programming Kamaljeet Saini wrote: > I got this following code from > "http://www.ruby-doc.org/core/classes/Socket.src/M002120.html" > > require 'socket' > include Socket::Constants > socket = Socket.new( AF_INET, SOCK_STREAM, 0 ) > sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' ) > socket.bind( sockaddr ) > socket.listen( 5 ) > client, client_sockaddr = socket.accept > data = client.recvfrom( 20 )[0].chomp > puts "I only received 20 bytes '#{data}'" > sleep 1 > socket.close > > How to make this code run ? Im trying to run from SciTE editor for ruby. > What correction i need to make to run this code so to get feel as how > this piece of code of socket works as seeing its output. http://www.catb.org/~esr/faqs/smart-questions.html#intro You didn't show any error. What makes you think it isn't running? The code above is a server, listening for incoming TCP connections on port 2200. A simpler way of implementing this is using the gserver.rb module which is included in the Ruby standard library. There is documentation at the top of this file. -- Posted via http://www.ruby-forum.com/.