socket.connect(x.split(':')[0], x.split(':')[1].to_i)
THis code does set the port. Just some bad variable naming.
x holds the adress to the server and the port. The method
String#split returns an array of strings split at the specified character. Here it is
":" which defines where the port begins. In the first element of the array we got the actual address, on the second we have the port.
That "script" you gave is very poorly written
Both from my perspective and from an overall ruby perspective. Too much junk in one place.