[TAG] help

Benjamin A. Okopnik ben at linuxgazette.net
Sun Jan 22 18:53:26 MSK 2006


On Sun, Jan 22, 2006 at 02:20:20PM +0000, Jimmy O'Regan wrote:
> 
> I looked at the code. It needs this patch to compile, at least with the 
> versions of gcc I tried:
> 
> ==== SNIP HERE tougher.diff.txt =====
> diff -ur orig/Socket.cpp ./Socket.cpp
> --- orig/Socket.cpp	2002-08-14 15:28:21.000000000 -0700
> +++ ./Socket.cpp	2006-01-22 06:04:12.000000000 -0800
> @@ -2,7 +2,7 @@
> 
> 
>  #include "Socket.h"
> -#include "string.h"
> +#include <iostream>
>  #include <string.h>
>  #include <errno.h>
>  #include <fcntl.h>
> diff -ur orig/simple_server_main.cpp ./simple_server_main.cpp
> --- orig/simple_server_main.cpp	2002-08-14 15:28:21.000000000 -0700
> +++ ./simple_server_main.cpp	2006-01-22 06:06:10.000000000 -0800
> @@ -1,6 +1,7 @@
>  #include "ServerSocket.h"
>  #include "SocketException.h"
>  #include <string>
> +#include <iostream>
> 
>  int main ( int argc, int argv[] )
>  {
> ===== SNIP HERE =====

Yep, that's what I'd found. Oddly enough, Rob included <iostream> in his
client code, but not in the server code (or Socket.h) - I guess he knew
about it but lost track at the last minute.

Maybe I should write an article about server/client pairs in Perl...
nah, that would be too easy. :)

----- servd ------------------------------------------------------------
#!/usr/bin/perl -w
# Created by Ben Okopnik on Sun Jan 22 10:48:47 EST 2006
use IO::Socket;

$s = IO::Socket::INET -> new( 	Proto => 'tcp',
								LocalPort => 654321,
								Listen => SOMAXCONN,
								Reuse => 1
) or die "Can't start server: $!\n";

while ( $c = $s -> accept() ){
	print $c scalar localtime, ": Welcome!\n";
	close $c
}
----- servd ------------------------------------------------------------

----- client -----------------------------------------------------------
#!/usr/bin/perl -w
# Created by Ben Okopnik on Sun Jan 22 10:50:50 EST 2006
use IO::Socket;

$h = IO::Socket::INET -> new(	PeerAddr => $ARGV[0]||"localhost",
								PeerPort => 654321
) or die "Can't connect: $!\n";

die "Can't fork: $!\n" unless defined( $kid = fork );
if ( $kid ){ print while <$h>; kill "TERM", $kid }
else { print $h while <STDIN> }
----- client -----------------------------------------------------------


* Ben Okopnik * Editor-in-Chief, Linux Gazette * http://linuxgazette.net *





More information about the TAG mailing list