[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Brother, can you spare a paradigm



At 4:52 PM -0500 on 12/3/96, Jerry LeVan wrote:


}Hmmm,
}Sat down last night and tried to open a socket to a remote
}machine. ( I am using the 68k perl tool+freePPP+OT 1.1.1).
}
}Not have a "fork" presents some difficulties :). Basically I
}decided to send a "GET /<cr><lf> to some machines running web stuff
}and grab the home page.
}
}The code looked something like this:
}$iaddr=inet_aton($remote);
}$paddr=sockaddr_in($port,$iaddr);
}$proto=getprotobyname('tcp');
}socket(SOCK,PF_INET,SOCK_STREAM,$proto) or die "socket: $!";
}connect(SOCK,$paddr) or die "connect: $!";
}select(SOCK); $|=1; select(STDOUT);
}
}#print "-->"; $line=<STDIN>; $line = $line ."\n";
}$line="GET /\n\012";
}print SOCK $line;
}$i=1;
}while($line=<SOCK>) {
}  print $i++, $line, "\n";
}}
}close(SOCK);
}
}Much to my surprise I only got back 1 long line, it looks like
}all of the <cr>'s where eaten , there was an "empty" box where
}the lines where supposed to end.(I assume it was the line feed.)
}Telneting to the port with a terminal program with "show control
}characters" enabled showed that each line was terminated with a
}<cr><lf> pair.
}
}Does this make any sense? Does command buffering ($|=1) make sense
}in the Mac environment.

Sure it does.  It works, too, as you see, since you got a reply (your
output was sent immediately).   But to quote the Camel (page 130), "This
has no effect on input buffering".

You're sure the client actually sent back properly terminated text?  Just
from reading what you've said, it looks as if the text was sent as Unix
text.  Otherwise I can't for the moment understand why $line contained what
it did.


}
}Does anyone out there have any MacPerl socket code that talks to a
}Unix Box.

There's tons of it.  It's something that my Mac does daily, and it speaks
http, ftp, nntp, smtp, and gopher with Unix (and other) boxes regularly.
Personally, unless you really want to reinvent the wheel, I'd look into one
of the available packages that does the protocol you're interested in.
I've ported both libwww-perl-5 (http, gopher, and lots of HTML and URL
handlers, and also does other protocols with help) and libnet-1.01 (FTP,
NNTP, SMTP, NTP, POP3, and more) to run under MacPerl.  You can find them
by following the links at my MacPerl site
<http://mors.gsfc.nasa.gov/MacPerl.html>.  If that doesn't cover what you
want to do, you can check at CPAN (start at <http://www.perl.com/>) and see
if the package you want already exists.  Then it's just a matter of porting
it to MacPerl, which ususally isn't that difficult.

}Would "threads" be a way that MacPerl could give an illusion of
}multithreading?
}(I thought I read that the MacOS now contained a thread package...

As I understand the situation at present, MacPerl can thread only with the
help of Userland Frontier, and only the OSA component version of MacPerl
can be used for this.

}
}--Jerry
}  levan@eagle.eku.edu


--------
Paul J. Schinder
NASA Goddard Space Flight Center
Code 693
Greenbelt, MD 20770
schinder@pjstoaster.pg.md.us