in reply to chat between client and server
Start it off simple. I like to build the server and telnet into it to start with. Gives you full control of the client while getting the server figured out. The following works, though i think there are probably some major issues with it memory wise. It is a nice simple start though.
#!/usr/bin/perl use strict; use warnings; use threads; use IO::Socket; my $server = IO::Socket::INET->new(LocalPort => 1300, Proto => 'tcp', Listen => 10, Reuse => 1); die "Failed to create socket: $!\n" unless $server; my $client; sub listen_to_client { while (my $get = <$client>) { print "client: $get"; }; print "Client closed\n"; } while ($client = $server->accept()) { print "Client connected\n"; threads->create("listen_to_client"); }
I ran it in one terminal, then telnet-ed in from two separate windows. Works like a charm.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: chat between client and server
by wavenator (Novice) on Oct 11, 2007 at 18:53 UTC | |
by eric256 (Parson) on Oct 11, 2007 at 20:47 UTC | |
by eric256 (Parson) on Oct 11, 2007 at 21:25 UTC | |
by zentara (Cardinal) on Oct 12, 2007 at 11:46 UTC |