perl tcp server script works, but no data.

E

Eli Sidwell

I am trying to get the following script to accept data, but I never see any.
Is this a flushing issue ?

Any help is appreciated.


#!/usr/bin/perl -w

$server_port = "5001";

use IO::Socket;

# make the socket
$server = IO::Socket::INET->new(LocalPort => $server_port,
Type => SOCK_STREAM,
Proto => 'tcp',
Reuse => 1,
Listen => 10 ) # or SOMAXCONN
or die "Couldn't be a tcp server on port $server_port : $@\n";

$server->autoflush();

while ($client = $server->accept()) {
# $client is the new connection

$client->recv($str, 1024)
or die "Can't recv: $!\n";

$client_ip = $client->peerhost;
$client_port = $client->peerport;

print "Data is: $str \n";
print "Client IP: $client_ip\n";
print "Client port: $client_port\n";
}

close($server);
 
E

Eli Sidwell

Still nothing, the $nread even comes up 0.

As far as the client, I tried to telnet a small file to that port and
then I wrote an app using the VB winsock to move text to that port.
Both times it opens the port and accepts the data (I think), I can get
the port and IP from perl but, I don't see any data.

Are there any good reference books on the perl socket with examples.
I have the orilly cookbook, but its a lot of theory.

Thanks
 
K

Kevin Collins

Please, no top posting...
Still nothing, the $nread even comes up 0.

As far as the client, I tried to telnet a small file to that port and
then I wrote an app using the VB winsock to move text to that port.
Both times it opens the port and accepts the data (I think), I can get
the port and IP from perl but, I don't see any data.

Are there any good reference books on the perl socket with examples.
I have the orilly cookbook, but its a lot of theory.
-snip-

perldoc 'perlipc' has a basic TCP client/server that I have used as the basis
for a couple of different things. Its not too complex.

Kevin
 
A

Anno Siegel

Kevin Collins said:
Please, no top posting...

-snip-

perldoc 'perlipc' has a basic TCP client/server that I have used as the basis
for a couple of different things. Its not too complex.

There's also Net::EasyTCP which covers simple TCP-based client/server
pairs.

Anno
 
E

Eli Sidwell

There's also Net::EasyTCP which covers simple TCP-based client/server
pairs.

Anno

I think that I have narrowed the problem, it seems that I don't
receive any data unless I send more than a 2k of stuff. I have seen
some postings that refer to flushing issues, how do I cause this code
to flush no matter what size data is received?

Thanks
 
B

Ben Morrow

Quoth (e-mail address removed) (Eli Sidwell):
I think that I have narrowed the problem, it seems that I don't
receive any data unless I send more than a 2k of stuff. I have seen
some postings that refer to flushing issues, how do I cause this code
to flush no matter what size data is received?

This sounds like a problem on the sending end... you need to flush after
each write. In perl, set $|=1.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top