Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!ucsd!sdd.hp.com!zaphod.mps.ohio-state.edu!ncar!mephisto!mcnc!uvaarpa!mmdf From: worley@compass.com (Dale Worley) Newsgroups: comp.lang.perl Subject: Closing down a connected network socket Message-ID: <1990Sep28.214349.18443@uvaarpa.Virginia.EDU> Date: 28 Sep 90 21:43:49 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: worley@compass.com Organization: The Internet Lines: 49 I'm trying to build a client that connects in sequence to several different servers. In order to not have to call socket and bind repeatedly, I want to just connect to each server and then do shutdown to disconnect. However, I'm having trouble getting it to work -- no value of the HOW parameter seems to leave the socket in a clean state that can execute a further connect without error. I don't know what I'm doing wrong. Has anybody done this who can tell me what the correct method is? Dale Worley Compass, Inc. worley@compass.com -- I don't practice what I preach, because I'm not the sort of person I'm preaching *to*. -- J. R. Dobbs The code I'm using is: #! /usr/local/bin/perl $port = 11009; @remotes = ('sn1987a', 'zeppelin', 'solen'); do '/compass/c/worley/perl-3.0/sys/socket.h' || die "Can't do sys/socket.h: $@"; $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $port) = getservbyname($port, 'tcp') unless $port =~ /^\d+$/; ($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname); $this = pack($sockaddr, &AF_INET, 0, $thisaddr); socket(S, &PF_INET, &SOCK_STREAM, $proto) || die "socket: $!"; bind(S, $this) || die "bind: $!"; select(S); $| = 1; select(stdout); foreach $remote (@remotes) { ($name, $aliases, $type, $len, $thataddr) = gethostbyname($remote); $that = pack($sockaddr, &AF_INET, $port, $thataddr); connect(S, $that) || die "connect: $!"; print ; shutdown(S, 2) || die "shutdown: $!"; }