January 2024
Intermediate to advanced
718 pages
20h 15m
English
Ruby is fluent in most of the Internet’s protocols, both low-level and high-level.
For those who enjoy groveling around at the network level, Ruby comes with a set of classes in the socket library (https://docs.ruby-lang.org/en/master/Socket.html). These give you access to TCP, UDP, SOCKS, and Unix domain sockets, as well as any additional socket types supported on your architecture. The library also provides helper classes to make writing servers easier. Here’s a simple program that gets information about our user website on a local web server using the HTTP OPTIONS request:
| | require "socket" |
| | |
| | client = TCPSocket.open("127.0.0.1", "www") |
| | client.send("OPTIONS /~dave/ HTTP/1.0\n\n", 0) |
Read now
Unlock full access