line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SmarTalk; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
#import |
4
|
1
|
|
|
1
|
|
7718
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
49
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
996
|
use IO::Socket; |
|
1
|
|
|
|
|
25093
|
|
|
1
|
|
|
|
|
6
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#export |
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ('all' => [ qw(new setServer serverUp setClient clientUp)]); |
13
|
|
|
|
|
|
|
our @EXPORT_OK = (@{$EXPORT_TAGS{'all'}}); |
14
|
|
|
|
|
|
|
our @EXPORT = qw(); |
15
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#declaration |
18
|
|
|
|
|
|
|
my ($tunnel,$settingServer,$settingClient,$pcremoto, |
19
|
|
|
|
|
|
|
$comunicazione,$paroleClient,$paroleServer,$class, |
20
|
|
|
|
|
|
|
$this,$usr,$cl); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#constructor |
23
|
|
|
|
|
|
|
sub new{ |
24
|
|
|
|
|
|
|
#new istance of class |
25
|
0
|
|
|
0
|
0
|
|
$class = shift; |
26
|
0
|
|
|
|
|
|
$usr = shift; |
27
|
0
|
|
|
|
|
|
$this = {username=>$usr->{username}, from=>$usr->{country}}; |
28
|
0
|
|
|
|
|
|
bless $this,$class; |
29
|
0
|
|
|
|
|
|
return $this; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
#method |
32
|
|
|
|
|
|
|
sub setServer{ |
33
|
|
|
|
|
|
|
#server object settings |
34
|
0
|
|
|
0
|
0
|
|
$this = shift; |
35
|
0
|
|
|
|
|
|
$settingServer = shift; |
36
|
0
|
|
|
|
|
|
$this->{porta} = $settingServer->{porta}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
#method |
39
|
|
|
|
|
|
|
sub serverUp{ |
40
|
|
|
|
|
|
|
#socket connection |
41
|
0
|
|
|
0
|
0
|
|
$tunnel = IO::Socket::INET->new |
42
|
|
|
|
|
|
|
( |
43
|
|
|
|
|
|
|
Proto => 'tcp', |
44
|
|
|
|
|
|
|
LocalPort => $this->{porta}, |
45
|
|
|
|
|
|
|
Listen => SOMAXCONN, |
46
|
|
|
|
|
|
|
Reuse => 1 |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
print "\nSmarTalk server online, port: $this->{porta}, |
50
|
|
|
|
|
|
|
protocol: tcp, wait for connections...\n\t"; |
51
|
0
|
0
|
|
|
|
|
die "\nProblems with port $this->{porta}... |
52
|
|
|
|
|
|
|
Port in use?\n\n" unless $tunnel; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
while ( $pcremoto = $tunnel->accept() ){ |
55
|
0
|
|
|
|
|
|
$pcremoto->autoflush(1); |
56
|
|
|
|
|
|
|
#fork for bidirectional communication |
57
|
0
|
|
|
|
|
|
$comunicazione = fork(); |
58
|
0
|
0
|
|
|
|
|
if ($comunicazione){ |
59
|
0
|
|
|
|
|
|
while ( defined( $paroleClient = <$pcremoto> ) ){ |
60
|
0
|
|
|
|
|
|
print STDOUT $paroleClient; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
kill( "TERM", $comunicazione ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else{ |
65
|
0
|
|
|
|
|
|
while ( defined( $this->{parolemie} = <> ) ){ |
66
|
0
|
|
|
|
|
|
$this->{message} = "*$this->{username}"."(from $this->{from}): "."$this->{parolemie}"; |
67
|
0
|
|
|
|
|
|
print $pcremoto "$this->{message}"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
#method |
73
|
|
|
|
|
|
|
sub setClient{ |
74
|
|
|
|
|
|
|
#base client object settings |
75
|
0
|
|
|
0
|
0
|
|
$this = shift; |
76
|
0
|
|
|
|
|
|
$settingClient = shift; |
77
|
0
|
|
|
|
|
|
$this->{macchinadiarrivo} = $settingClient->{server}, |
78
|
|
|
|
|
|
|
$this->{portadiarrivo} = $settingClient->{porta}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
#method |
81
|
|
|
|
|
|
|
sub clientUp{ |
82
|
|
|
|
|
|
|
#socket connection |
83
|
0
|
|
|
0
|
0
|
|
$this = shift; |
84
|
0
|
|
|
|
|
|
$tunnel = IO::Socket::INET->new( |
85
|
|
|
|
|
|
|
Proto => 'tcp', |
86
|
|
|
|
|
|
|
PeerAddr => $this->{macchinadiarrivo}, |
87
|
|
|
|
|
|
|
PeerPort => $this->{portadiarrivo} |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if ($tunnel){ |
91
|
0
|
0
|
|
|
|
|
$tunnel->autoflush(1) or die "Can't connect to port $this->{portadiarrivo} on |
92
|
|
|
|
|
|
|
$this->{macchinadiarrivo}"; |
93
|
0
|
|
|
|
|
|
print "Connected to SmarTalk server $this->{macchinadiarrivo} on port: $this->{portadiarrivo}, |
94
|
|
|
|
|
|
|
protocol: tcp...\n Talk!...\n"; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#fork for bidirectional communication |
97
|
0
|
|
|
|
|
|
$comunicazione = fork(); |
98
|
0
|
0
|
|
|
|
|
if ($comunicazione){ |
99
|
0
|
|
|
|
|
|
while ( defined ( $paroleServer = <$tunnel> ) ){ |
100
|
0
|
|
|
|
|
|
print STDOUT $paroleServer; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
kill( "TERM", $comunicazione ); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else{ |
105
|
0
|
|
|
|
|
|
print $tunnel "Client $this->{username} from $this->{from} connected!\n Talk!...\n\r"; |
106
|
0
|
|
|
|
|
|
while ( defined( $this->{parolemie} = ) ){ |
107
|
0
|
|
|
|
|
|
chomp $this->{parolemie}; |
108
|
0
|
|
|
|
|
|
$this->{message} = "*$this->{username}"."(from $this->{from}): "."$this->{parolemie}"; |
109
|
0
|
|
|
|
|
|
print $tunnel "$this->{message}\n\r"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
else{ |
114
|
0
|
|
|
|
|
|
print STDOUT "\nNo connection... |
115
|
|
|
|
|
|
|
Server $this->{macchinadiarrivo} OFFLINE on port $this->{portadiarrivo}\n\n"; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
1; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
__END__ |