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) > self.sckt.bind((self.CFG['smsc']['local_host'], > self.CFG['smsc']['local_port'])) > self.sckt.connect((self.CFG['smsc']['remote_host'], > self.CFG['smsc']['remote_port'])) > self.sckt.send(mex) > recv = self.sckt.recv(4096) > self.sckt.close() > > 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) s.write(mex) 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. http://www.ruby-doc.org/docs/ProgrammingRuby/html/lib_network.html -- Posted via http://www.ruby-forum.com/.