Ruby Sockets

November 3, 2009

For the last few days I’ve been writing a simple IRC bot in Ruby. I have noticed however that the documentation for Ruby Sockets is quite poor, so I thought I’d post a bit about using Ruby Sockets here.

RubySocket
These are all the main classes that deal with sockets, with the exception of IO.

BasicSocket
This is the base socket class which defines a few simple methods, pretty useless on its own.

Socket
This class contains everything you need to work with sockets, however if you intend to use a TCP, UDP, SOCKS or UNIX socket you will probably be better off using one of the other classes.
http://en.wikipedia.org/wiki/Internet_socket

UNIXSocket & UNIXServer
These two classes make it easy to quickly work with UNIX sockets.
http://en.wikipedia.org/wiki/Unix_socket

IPSocket
This is the base class for working with IPv4 and IPv6 addresses.
http://en.wikipedia.org/wiki/Internet_Protocol

UDPSocket
As the name suggests this provides everything you need to work with UDP.
http://en.wikipedia.org/wiki/User_Datagram_Protocol

TCPSocket & TCPServer
Everything you need to deal with TCP is in these two classes as TCP is the most common internet protocol, this will probably be the class you will most use.
http://en.wikipedia.org/wiki/Transmission_Control_Protocol

SOCKSSocket
http://en.wikipedia.org/wiki/SOCKS

For the most part you will only ever make use of TCPSocket, TCPServer and UDPSocket. In my next post I’ll show some examples of using these and Socket.


Follow

Get every new post delivered to your Inbox.