Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Winsock connect problem in perl!!!

by madtoperl (Hermit)
on May 16, 2006 at 10:39 UTC ( [id://549709]=perlquestion: print w/replies, xml ) Need Help??

madtoperl has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Winsock connect problem in perl!!!
by Corion (Patriarch) on May 16, 2006 at 11:07 UTC

    Don't use <$client> to read from a client socket. Perl tries to read 4k of data (or less, or more) before it starts to look for a newline in the data. You want to wait until data is available and then read all the available data but not more. You should use the read() and write() calls for that. If you plan to handle more than one client at the same time, you will need to handle more than one socket, which is what the select function is for, or, more nicely encapsulated, the IO::Select module.

    For testing such stuff, I found the telnet programs to be very useful as they allow you to manually enter the data to your server so you can conveniently see what actually gets sent.

Re: Winsock connect problem in perl!!!
by chargrill (Parson) on Oct 07, 2006 at 02:13 UTC

    Extremely easy to find.

    Please reference this link to see the original question by Daniel Moree.

    Perl socket problem 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 tc +p. 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 boo +k 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 pe +rl 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 Win +sock. 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

    This is ridiculous.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://549709]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-19 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found