TCP Listener on Windows XP

C

Colin Robbins

I have a network application that works fine on Linux, and I want to run it
on on a Windows XP machine. For some reason I cannot get the TCP listener
to respond.

I have cut the code down to the bare minimum to try and debug...

use IO::Socket;
use Net::hostent;
$PORT = 2345;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";
while ($client = $server->accept()) {
$hostinfo = gethostbyaddr($client->peeraddr);
printf "Connect from %s\n", $hostinfo->name ||
$client->peerhost;
$line = <$client>;
print "Got: $line \n";
close $client;
}

When I run this, and connect a client, I get as far as the "Connect from..."
message, but the $line=<$client> never returns anything.

Any ideas why this will not work on XP?

I am using ActivState perl 5.8.0.
 
C

Colin Robbins

How odd!
I tried it with Finger, and get exactly the same failed result as before

[Server E:\Perl\CJR\test.pl accepting clients]
Connect from JUPITER.robbins4.freeserve.co.uk

The connection gets made, but that is all - no data.
The firewall is off (I assume the firewall would block the connection
attempt anyway).

Also, I am not sure what you meant by your comment about Win32 and XP. I
thought XP was Win32!!!

Thanks for the help.

Colin
 
T

Thomas Kratz

Colin said:
I have a network application that works fine on Linux, and I want to run it
on on a Windows XP machine. For some reason I cannot get the TCP listener
to respond.

I have cut the code down to the bare minimum to try and debug...

use IO::Socket;
use Net::hostent;
$PORT = 2345;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";
while ($client = $server->accept()) {
$hostinfo = gethostbyaddr($client->peeraddr);
printf "Connect from %s\n", $hostinfo->name ||
$client->peerhost;
$line = <$client>;
print "Got: $line \n";
close $client;
}

When I run this, and connect a client, I get as far as the "Connect from..."
message, but the $line=<$client> never returns anything.

Any ideas why this will not work on XP?

I am using ActivState perl 5.8.0.

I copied and pasted the code to an XP machine and did a 'telnet
localhost 2345'. Worked like a charm. Didn't have a Unix machine to
test it from there.

I think mooseshoes is right in assuming that the client doesn't send a
valid line ending.

Thomas
 
J

James Willmore

Colin Robbins said:
I have a network application that works fine on Linux, and I want to run it
on on a Windows XP machine. For some reason I cannot get the TCP listener
to respond.

I have cut the code down to the bare minimum to try and debug...

use IO::Socket;
use Net::hostent;
$PORT = 2345;
$server = IO::Socket::INET->new( Proto => 'tcp',
LocalPort => $PORT,
Listen => SOMAXCONN,
Reuse => 1);
die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";
while ($client = $server->accept()) {
$hostinfo = gethostbyaddr($client->peeraddr);
printf "Connect from %s\n", $hostinfo->name ||
$client->peerhost;
$line = <$client>;
print "Got: $line \n";
close $client;
}

When I run this, and connect a client, I get as far as the "Connect from..."
message, but the $line=<$client> never returns anything.

Any ideas why this will not work on XP?

I am using ActivState perl 5.8.0.


The code is fine. I tested with a W2K box and connected just fine
using Linux. However, I found that the native W2K telnet client
doesn't echo. The line is printed on the server side, but the client
.... well ... you have no idea what you typed until you hit enter.

That's the key ... are you using a client that sends a new line at the
end of a line -or- is it some other character? That may be the issue.

Jim
 
C

Colin Robbins

Thanks for the help.

I ran my code on Windows 2003 server without problem.
As you suggest, looks like XP was the issue.

Thanks again.

Colin


Purl Gurl said:
Colin said:
(snipped)
I tried it with Finger, and get exactly the same failed result as before
[Server E:\Perl\CJR\test.pl accepting clients]
Connect from JUPITER.robbins4.freeserve.co.uk



Like another here who responded, I can connect through telnet, through
finger, through any method which does not wait for a response and
terminates a request with ENTER, otherwords, a newline.

Run your local machine telnet client.

Connect to 127.0.0.1 port 2345

Type in at your telnet command line: testing

Press ENTER

Check your script results, independent of your telnet client.
Your results will not be displayed in your connection client.

Be sure you understand that, you will NOT see results in
your connection client, such as finger or telnet.

Also, I am not sure what you meant by your comment about Win32 and XP. I
thought XP was Win32!!!

Win XP is the slowest most cumbersome Win GUI to date. It is memory
intensive and cpu intensive. Stable yes, but slow as a snail on ice.

Here is a real problem. If you are to do any serious Perl programming
using a Win system, you need true MSDOS access. You do not have this.

This is an example of what you may do using Win 32 system and cannot
do using newer WinNT, which is what your XP is save for graphical
and audio enhancements which eat up all your memory and cpu time.
Win XP is an attempt to adapt WinNT to home users. This attempt
fails with significant annoyance.


Try doing this,

Open a _true_ MSDOS window. Start your socket client. You will see,

[Server test.pl accepting clients]

Open another MSDOS window. Start your telnet client.

Close this MSDOS window in which you started your telnet client.

Type into your telnet command line, test

Press ENTER

In your MSDOS window for your socket client, you will read
your script results real time.

This methodology will afford you an ability to test various
connection clients, such as time, echo, ping, email, get,
tcp terminal, ident, quote, daytime and others like port
probe and email validate.

Many of those will not work with your Perl socket client
as they wait for a response, which your code does not provide.

As you can see, if you cannot access _true_ MSDOS, you will not
be able to run those tests, will not be able to observe results
real time, independent of any connection client.

True MSDOS allows you to literally see what your program is
doing directly with no interference by a connection client
nor by WinXP.

Your WinXP runs DOS emulation. You have no way of knowing if
your WinXP emulation is interferring. Otherwords, your code
is working but you cannot "see" this because of WinXP.

Best test is to drop out of your Win GUI directly into
true MSDOS and work from there. Can you do this with WinXP?

So you see, Win 32 system is infinitely superior from a
programmer's point of view. On my system, I can pull up
true MSDOS without closing my Win GUI, or I can close
my Win GUI and drop into MSDOS, then reboot my GUI
when finished. No machine reboot is needed nor is a
MSDOS boot disk needed, as with WinXP or WinNT.

Your code works. Your system or connection client is at fault.

Like I said, you need to upgrade to Win 32 system if you want
to be a serious Perl programmer, within the context of working
with and developing on, a Windows system.


Purl Gurl
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top