> -----Original Message-----
> From: Dan Grossman [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 3:51 PM
> To: [EMAIL PROTECTED]
> Subject: Cooperating with WINSOCK using Socket::
> 
> 
> Hello,
> 
> I'm hoping someone can help me with an INET Socket question.  
> I have the following socket setup and subroutine to receive 
> data from a
> Server:
> 
> # connection protocol
> if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
> die "No port" unless $port;
> $iaddr = inet_aton($remote)               or die "no host: $remote";
> my $paddr = sockaddr_in($port, $iaddr);
> 
> $proto = getprotobyname('tcp');
> socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "socket: $!";
> connect(SOCK, $paddr)                      or die "connect: $!";
> 

I suggest you use IO::Socket instead of all this jazz. It handles all this
setup stuff for you in one call.

> # Client subroutine
> sub receiveServerResponse() {
>     my $line = "";
>     while ($line = <SOCK>) {
>         if ($line) {
>             print "\tReceived: $line";
>             return $line;
>         }
>     }
> }
> 
> The protocol I am following insists on having a LF at the end 
> of all messages, but some (Windows-based) servers with whom I 
> am attempting to cooperate are incorrectly sending messages 
> ending with CR.  How can I get 
> 
>       while ($line = <SOCK>)
> 
> to recognize a "line" ending with CR?

Well, the $/ variable determines what a "line" is (see perldoc perlvar). But
you can't use a regex.

So you may have to use read() instead and process 1 char at a time.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to