Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Problems reading back from socket

by rupesh (Hermit)
on Nov 16, 2005 at 13:00 UTC ( #509017=note: print w/ replies, xml ) Need Help??


in reply to Problems reading back from socket

A basic client and server, socket implementation(untested).

Server:

use strict; use IO::Socket; my $sock = new IO::Socket::INET (LocalHost => 'localhost', LocalPort => 5004, Proto => 'tcp', Listen => 5, Reuse => 1 + ); die "Socket could not be created. Reason: $!" unless $sock; my ($new_sock, $buf); while ($new_sock = $sock->accept()) { print "Connection from ", $new_sock->peerhost, ": on port ", $new_s +ock->peerport,"\n"; print $new_sock "Hello from the server"; while (defined ($buf = <$new_sock>)) { print $buf; } } close ($sock);
Client:
use strict; use IO::Socket; my $line; my $socket = new IO::Socket::INET ( PeerAddr => 'localhost', PeerPort => '5004', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $socket; $socket->recv($line, 80); print "$line"; print $socket "Hello from the Client!\n"; close($socket);


Cheers,
Rupesh.


Comment on Re: Problems reading back from socket
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-12-18 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (49 votes), past polls