Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

RE: Socket programming

by Zarathustra (Beadle)
on Oct 07, 2000 at 04:58 UTC ( #35705=note: print w/ replies, xml ) Need Help??


in reply to Socket programming

Looks like your mistake is using the accept method in your client.

Don't do that.

(c8=

#!/usr/bin/perl -w use IO::Socket; # create a tcp connection to the specified host and port $client = IO::Socket::INET->new( Proto => "tcp", PeerAddr => 'localhost', PeerPort => '6969' ), or die "can't connect to server: $!"; print "[Client $0 connected to server]\n"; print $client "READY\n"; # as a client, you are not accepting connections # while ($server = $client->accept()) { # listen on and talk into your open socket instead while (<$client>) { if (/GO/i) { srand; # seed the random number function $num = int (rand 4); # get a random integer, 1 through 104 if ($num == 1) { print $client "Rock\n"; } elsif ($num == 2) { print $client "Paper\n"; } elsif ($num == 3) { print $client "Scissors\n"; } } if (/STOP/i) { last; } } close $client;


Comment on RE: Socket programming
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2015-07-06 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (68 votes), past polls