in reply to TCP Socket not receiving.

while(<$new_sock>) {

You are using readline to read from your socket. That means that it will read bytes until it sees a byte or bytes that match the current value of $/ (the input separator), which by default is set to "\n".

For networking purposes, a newline is defined to be ascii(13-decimal) + ascii(10-decimal)

As your data doesn't contain a newline character, those reads continue to wait.

If you redefined the input separator to be EOT (ie. $/ = chr(4);), then your code would probably work as expected.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: TCP Socket not receiving.
by ghopwood (Initiate) on Jul 24, 2012 at 16:48 UTC
    That was exactly it!

    You know in the back of my mind I had this nagging suspicion it was lack of the return\line feed.

    Its been so long since I've coded in Perl (or not enough coffee), I just couldn't put it into a solidly formed idea, or find it jumping out at me in the docs.

    Heres the working code. Thanks.
    #!/usr/bin/perl -w use strict; use POE qw(Component::Server::TCP); POE::Component::Server::TCP->new( Alias => 'linda_server', Port => 2000, Concurrency => 5, ClientConnected => \&event_tcp_conn, ClientDisconnected => \&event_tcp_disconn, ClientInput => \&event_tcp_incoming, ClientFilter => [ "POE::Filter::Line", Literal => chr(4) ], ); print "Starting POE Kernel.\n"; $poe_kernel->run(); sub event_tcp_conn { my ($heap,$kernel) = @_[HEAP, KERNEL]; print "Connection: $heap->{remote_ip} Accepted\n"; } sub event_tcp_disconn { my ($heap,$kernel) = @_[HEAP, KERNEL]; print "Disconnect: $heap->{remote_ip}.\n"; } sub event_tcp_incoming { my ($heap, $kernel, $input) = @_[HEAP, KERNEL, ARG0]; print "Received: $heap->{remote_ip} : $input\n"; } __END__