From: Johannes Steigerwald Date: 2003-09-29T18:14:37+09:00 Subject: Ruby Newbie's Question: Sockets - searching for equivalent to a perl programme Hi all, I have been desperately trying to convert the following perl programme to Ruby. What should I use for the functions sockaddr_in (maybe the famous pack("snCaaaa8") ?) and syswrite. Thank for assisting me! Johannes # Here's the perl programme I have been trying to convert to Ruby use IO::Socket; # snip # $ServerPort=8530; $scheme_exp='(ivel-window-get-active-vref)'; if (!defined $Proto) { $iaddr = inet_aton(hostname()); $Proto = getprotobyname('tcp'); } $paddr = sockaddr_in($ServerPort, $iaddr); #Socket settings. if (!(socket(SOCK, &PF_INET, &SOCK_STREAM, $Proto))) { warn "socket: $!\n"; return "socket: $!\n"; } if (!(defined $ServerPort) || !(connect(SOCK,$paddr))) { print "Error: could not open socket to Visual.\n"; print "Probably because Visual either crashed or was killed.\n"; exit 0; } select(SOCK); $|=1; select(STDOUT); $cmd = "#S(netutl-client-msg-header netutl-client-msg-type/gui-blocking \"Perl client\")\r\n"; syswrite(SOCK,$cmd,length($cmd)); select(SOCK); $|=1; select(STDOUT); $cmd = "($scheme_exp)\r\n"; syswrite(SOCK,$cmd,length($cmd)); SOCK -> autoflush(); $ret_val = ""; while() { $ret_val .= $_; } shutdown(SOCK,2); chomp($ret_val); return($ret_val); -- ------------------------------------------------------------------- |Johannes Steigerwald | Oc� Printing Systems GmbH, TEC35| |phone: +49-8121-72-4912 | Siemensallee 2 | |fax: +49-8121-72-3173 | D-85586 Poing - Germany | |johannes.steigerwald@ops.de | www.oce.com | -------------------------------------------------------------------