Devis Battisti wrote:
I’d want to port this code from python to ruby:
self.sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
recv = self.sckt.recv(4096)
The remote host is a router for an SMSC service.
The script is tested and works correctly.
I don’t understand if I’ve to create a client or a server socket…
Since you are using TCP and calling ‘connect’, it’s a client socket.
However, they have (unusually) decided to bind the socket to a specific
local port. This might be because of firewall rules.
Without this you could just do:
s = TCPSocket.new(cfg.remote_host, cfg.remote_port)
recv = s.read(4096)
If you really need to bind the local port for an outbound connection, I
think you’ll have to use the lower-level Socket class directly, which is
not particularly well documented, but should correspond roughly to your
python code. Unfortunately you’ll need to do some sockaddr packing.