Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem with perl sockets

1 view
Skip to first unread message

Daniel Moree

unread,
Oct 4, 2005, 7:00:36 PM10/4/05
to
I'm attempting to use a perl script to interface with my Visual Basic 6
program using Winsock. I've got my program setup to connect and works
great if i connect to another winsock program, but it acts funny
connecting to my perl script. The Perl code is below:

#!c:/Perl/bin/Perl.exe
use IO::Socket;
$server = IO::Socket::INET->new(LocalAddr => '10.40.0.10',
LocalPort => '8777',
Proto => 'tcp',
Listen => 1,
Reuse => 1);

die "ERROR: $!\n" unless $server;

print "Waiting on connections...\n";
while($client = $server->accept()){
print "Connection made, reading data...\n";
print <$client>;
print "Connection closed...\n";
}

$server->close();

All the program is supposed to do is open a socket on port 8777 for tcp.
Listen for any incomming connections then read the one line of data
comming in. I've read on the internet and in my perl in a nutshell book
that the above code should work. But they all say the same thing. You
must get the line of data and scan it for a character that lets the perl
script that the line is done. Problem is, when the script runs, i get as
far a connection made then it will do nothing until i close the VB Winsock.

Anyone got a reader for sockets that will know when to stop reading? I
haven't found any examples on the internet on how to do it, just that
everyone says it can be done. I'd really appreciate the help!

Daniel Moree

John Smith

unread,
Oct 22, 2005, 5:16:00 AM10/22/05
to D_M...@shadowbranch.com
Couple of things to consider:

1) Perl 5.8 tends to buffer output. You can adjust this by altering the
variable "$|", as such:

$|=8; # this will set the buffer to flush every 8 characters. Low
numbers are fine.


2) Also, if you aren't already, you may want to have your VB program
send vbCRLF at the end of each line of data sent across the socket
connection. Perl tends to look for 0x0d0a ("\r\n" in perl-speak) to
delimit text lines.

3) You might consider calling

close($client);
before
print "Connection closed...\n";


For a more thorough walkthrough of Perl socket stuff, you might try the
POD (plain old documentation), available here:
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Pod/perlipc.html#sockets__client_server_communication


Hope this helps.

Joe Smith

unread,
Oct 23, 2005, 6:17:27 AM10/23/05
to
John Smith wrote:

> 1) Perl 5.8 tends to buffer output. You can adjust this by altering the
> variable "$|", as such:
>
> $|=8; # this will set the buffer to flush every 8 characters. Low
> numbers are fine.

Where did you come up with that idea?
The special variable $| takes on only two values; 0 and 1.

perl -le 'print $|; $|=8; print $|'
0
1

Setting $|=8 is no different from setting $|=1.

Perhaps you are thinking of $/ = \8 which is the input record separator.

-Joe

John Smith

unread,
Oct 26, 2005, 4:19:22 AM10/26/05
to
My Bad.
I misread some anecdotal documentation somewhere in the past.
perlvar.html set me straight. Oddly, setting this to 8 (or 1 or 244)
would, most likely, solved his issue. Alas.
0 new messages