-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspkmus_server.pl
More file actions
30 lines (23 loc) · 924 Bytes
/
spkmus_server.pl
File metadata and controls
30 lines (23 loc) · 924 Bytes
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
#!/usr/bin/perl -w
# spkmus server
# Listens to an incoming connection and launches the spkmus script
use strict;
use Socket;
my $port = shift || 10003;
my $proto = getprotobyname('tcp');
socket(SERVER,PF_INET,SOCK_STREAM,$proto) or die("Cannot create socket: $!");
setsockopt(SERVER,SOL_SOCKET,SO_REUSEADDR,1) or die("Cannot setup socket: $!");
my $paddr = sockaddr_in($port, INADDR_ANY);
bind(SERVER,$paddr) or die("Cannot bind server to port: $!");
listen(SERVER,SOMAXCONN) or die("Cannot listen at port: $!");
print("Spkmus server listening on port $port");
my $client_addr;
while($client_addr = accept(CLIENT,SERVER)){
my ($client_port,$client_ip) = sockaddr_in($client_addr);
my $client_ipnum = inet_ntoa($client_ip);
my $client_host = gethostbyaddr($client_ip,AF_INET);
print("$client_host","[$client_ipnum]"," is connected!");
print CLIENT "Start";
close CLIENT;
`./spkmus.sh`;
}