Leser: 2
|< 1 2 >| | 17 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
sub main_connection {
my $text = shift;#prompt-msg
sleep(30) unless $FST;#provide serverflooding
$FST = 0;
print "$text\n";
$SPIN = shake_hands();
login();
#use select to have a non-blocking socket
my $sock = new IO::Select( $SPIN );
main_loop($sock);
} #sub main_connection
sub main_loop {
my $sock = shift;
my $died = 0;#check flag
while (1) {
#get data from socket, if there some
while ((my @ready = $sock->can_read(30))) {
#print "test1\n";
for my $fh (@ready) {#checkout readable fhs
if($fh == $SPIN) {
my $input;
unless(sysread($SPIN,$input,2048)) { $died = 1 };
last if $died;
if($input) {
#print "test2\n";
ping_check();
#in some cases we've more than one cmd in a line
#so we've to split them by \n, cause server seperates by \n
my @cmds = split /\n/, $input;
for my $line (@cmds) {
open_log() unless check_log("logs/$logfile");
start($line);
#print "test3\n";
}
} else {
print "unknow socketerror...\n";#syswrite returns 1, but we haven't some input?
}
last;
}
}
last if $died;
}
last if $died;
ping_check() or last;
print "Nichts passiert!\n";
}
main_connection('Socketerror, trying to reconnect..');
} #main_loop()
QuoteBad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at C:/Perl/lib/Socket.pm line 373.
Quoterecv: Unknown error at C:\Dokumente und Einstellungen\Operator\Eigene Dateien\Public\Homepage\cgi-bin\iosocketclient.cgi line 18.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser); use IO::Socket; my ( $HOSTNAME, $PORTNO, $MAXLEN, $nachricht ); $HOSTNAME = '127.0.0.1' ; $PORTNO = 5151; $MAXLEN = 1024; $nachricht = 'Hallo Computer'; socket ( SOCKET, PF_INET , SOCK_DGRAM, getprotobyname ( 'udp' ) ) or die "socket: $!"; my $ipaddr = inet_aton ( $HOSTNAME ); my $portaddr = sockaddr_in ( $PORTNO, $ipaddr ); send ( SOCKET, $nachricht , 0, $portaddr ) == length ( $nachricht ) or die "cannot send to $HOSTNAME($PORTNO): $!"; $portaddr = recv ( SOCKET, $nachricht, $MAXLEN, 0 ) or die "recv: $!"; ( $PORTNO, $ipaddr ) = sockaddr_in ( $portaddr ); my $host = gethostbyaddr( $ipaddr, AF_INET ); print "$host($PORTNO) said $nachricht$/";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
use IO::Socket; my $sock = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '7070', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $sock; my $new_sock = $sock->accept(); while(<$new_sock>) { print $_; } close($sock);
1 2 3 4 5 6 7 8 9
use IO::Socket; my $sock = new IO::Socket::INET ( PeerAddr => '127.0.0.1', PeerPort => '7070', Proto => 'tcp', ); die "Could not create socket: $!\n" unless $sock; print $sock "Hello there!\n"; close($sock);
QuoteCould not create socket: Unknown error
Could not create socket: Connection refused
|< 1 2 >| | 17 Einträge, 2 Seiten |