Skip to content

Instantly share code, notes, and snippets.

```ruby
require 'socket'
# Create the server using the Socket class
# AF_INET: using IP protocol
# SOCK_STREAM: using TCP
server_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
# Set the socket address
sockaddr = Socket.pack_sockaddr_in( 2200, 'localhost' )

Socket

[Document on ruby-doc.org] [ruby_doc]

Introduction

Ruby provides a standard library Socket for networking programming in lower layer, such as TCP and UDP. There are also other libraries for application layers like HTTP, FTP and TELNET, they are not included in this tutorial.

What is Socket

require "socket"
echo_server = TCPServer.new('localhost', 2200)
socket_list = Array.new
socket_list.push echo_server
loop do
return_array = select( socket_list, nil, nil, nil )
res = return_array[0][0]
if res == echo_server
client=res.accept
socket_list.push client
require "socket"
@echo_server = TCPServer.new('localhost', 2200)
@socket_list = Array.new
@socket_list.push @echo_server
loop do
return_array = select( @socket_list, nil, nil, nil )
res = return_array[0][0]
if res == @echo_server
client=res.accept
@socket_list.push client
require "socket"
echo_server = TCPServer.new('localhost', 2200)
loop do
Thread.start(echo_server.accept) do |client|
puts "#{client.peeraddr[2]}:#{client.peeraddr[1]} is connected"
loop do
data = client.recvfrom( 20 )[0].chomp
if data =="exit"
client.puts "bye!"
puts "#{client.peeraddr[2]}:#{client.peeraddr[1]} is disconnect"

Socket

[Document on ruby-doc.org] [ruby_doc]

Introduction

Ruby provides a standard library Socket for networking programming in lower layer, such as TCP and UDP. There are also other libraries for application layers like HTTP, FTP and TELNET, they are not included in this tutorial.

What is Socket

@ruanwz
ruanwz / uml.txt
Created September 16, 2010 08:03
[IO]^[BasicSocket], [BasicSocket]^[Socket], [BasicSocket]^[UNIXSocket],
[BasicSocket]^[IPSocket]
[IPSocket]^[UDPSocket],[UDPSocket]^[UDPServer]
[IPSocket]^[TCPSocket],[TCPSocket]^[TCPServer]
[UNIXSocket]^[UNIXServer],
[StandardError]^[SocketError]
[FFI::Struct]^[AddrInfo]
[FFI::Struct]^[SockAddr_In]
[FFI::Struct]^[SockAddr_Un]
[FFI::Struct]^[Servent]
The following lines are the output of following command:
cucumber features > ~/gstore_features_output.txt
Feature: object
As a google storeage api user
I want to create objects in a bucket
So that I can perform other operation on the objects
Scenario: create an object in an empty bucket # features/object.feature:6
Sinatra is designed to need friends
no presets
pure ruby
rack-lover
Rack is the best friend
Rack::Session::Cookie
Rack::CommonLogger
Rack::MethodOverride
rack-contrib
require 'rubygems'
require 'gcal4ruby'
include GCal4Ruby
service = Service.new
service.authenticate("", "")
#2. Get Calendar List
# puts calendars = service.calendars
cals = Calendar.find(service, {:title => "RMU September Session 1"})
puts cals.first.to_xml
#event = Event.new(service, {:calendar => cal, :title => "Soccer Game", :start => Time.parse("12-06-2010 at 12:30 PM"), :where => "Merry Playfields"})