File indexing completed on 2025-01-19 06:55:04
0001 #!/usr/bin/perl 0002 0003 # Main variable server 0004 0005 require("kmuddy-usock-client.pl"); 0006 0007 # Initialise connection to kmuddy's variable server 0008 initVariableSocket(); 0009 0010 0011 0012 $varserv_port = 41233; 0013 0014 use Socket; 0015 use Carp; 0016 0017 $| = 1; # Disable output buffering 0018 0019 if (getservbyport($varserv_port,"tcp")) 0020 { 0021 die("Port already in use\n"); 0022 0023 } # endif port in use 0024 0025 $prototype = getprotobyname("tcp"); 0026 0027 socket(SERV_SOCKET, 0028 PF_INET, 0029 SOCK_STREAM, 0030 $prototype) || die("Socket creation failure\n"); 0031 0032 setsockopt(SERV_SOCKET, 0033 SOL_SOCKET, 0034 SO_REUSEADDR, 0035 pack("l", 1)) || die "Failure in setsockopt(): $!"; 0036 0037 bind(SERV_SOCKET, 0038 sockaddr_in($varserv_port, 0039 INADDR_ANY)) || die("Cannot bind socket\n"); 0040 0041 listen(SERV_SOCKET,5) || die("Cannot listen on socket\n"); 0042 0043 0044 print("Temporary test server for Kmuddy event notifications\n"); 0045 print("Server is running\n"); 0046 0047 %values = (); 0048 0049 while (1) 0050 { 0051 if (!($clientaddr = accept(MYCONNECTION,SERV_SOCKET))) 0052 { 0053 print("Can't accept connection\n"); 0054 die(); 0055 } 0056 else 0057 { 0058 select(MYCONNECTION); 0059 0060 $| = 1; # Disable buffering on socket 0061 0062 select(STDOUT); 0063 0064 if (($input = <MYCONNECTION>) ne "") 0065 { 0066 chomp($input); 0067 0068 print ("Received: '$input'\n"); 0069 print ("Sending: 'bounce'\n"); 0070 0071 sendCommand("bounce"); 0072 } # endif something received 0073 0074 close(MYCONNECTION); 0075 } 0076 0077 } # endwhile more connections waiting 0078 0079 close(SERV_SOCKET); 0080 0081 # Terminate connection to kmuddy's variable server 0082 closeVariableSocket();