Skip to content

Instantly share code, notes, and snippets.

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

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

```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

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

*bundles.txt* Bundles Version 0.1
These are the bundles installed on your system, along with their
versions and release dates. Downloaded on Mon Sep 20 14:40:42 +0800 2010.
A version number of 'n/a' means upstream hasn't tagged any releases.
- |surround| v1.90-1-g27710a2 2010-09-09
- |taglist| n/a 2007-09-21
- |command-t| 0.8.1-2-g195dedc 2010-09-14
- |ruby| vim7.3-21-g5560a2f 2010-09-12
@ruanwz
ruanwz / .vimrc
Created September 21, 2010 01:11
nmap <silent> <Leader>t :TlistToggle<CR>
nmap <silent> <Leader>n :NERDTreeToggle<CR>
@ruanwz
ruanwz / .vimrc
Created September 21, 2010 04:15
" vimsy's .vimrc
"
" This is my vimrc as of August 2010. The vim-update-bundles parts are
" closer the bottom.
"
" Don't use abbreviations! Spelling things out makes grepping easy.
" Let Pathogen bring in all the plugins
filetype off
call pathogen#runtime_append_all_bundles()
@ruanwz
ruanwz / .vimrc
Created September 25, 2010 14:24
" Don't use abbreviations! Spelling things out makes grepping easy.
" Let Pathogen bring in all the plugins
filetype off
call pathogen#runtime_append_all_bundles()
set modelines=0
filetype indent plugin on
syntax on