This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
/
LinnDS-jukebox-daemon.php
146 lines (111 loc) · 3.02 KB
/
LinnDS-jukebox-daemon.php
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env php
<?php
/*!
* LinnDS-jukebox
*
* Copyright (c) 2015-2016 Henrik Tolbøl, http://tolbøl.dk
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/
require_once("setup.php");
require_once("SocketServer.php");
require_once("LinnDSClientSocket.php");
require_once("LPECClientSocket.php");
//require_once("wsListeningSocket.php");
require_once("ServerState.php");
class LinnDSListeningSocket extends ListeningSocket
{
private $lPECListeningSocket;
public function setLPECListeningSocket($LPEC)
{
$this->lPECListeningSocket = $LPEC;
}
public function getLPECListeningSocket()
{
return $this->lPECListeningSocket;
}
}
/*
class LinnDSwsListeningSocket extends wsListeningSocket
{
private $lPECListeningSocket;
public function setLPECListeningSocket($LPEC)
{
$this->lPECListeningSocket = $LPEC;
}
public function getLPECListeningSocket()
{
return $this->lPECListeningSocket;
}
}
*/
class LPECListeningSocket extends ListeningSocket
{
protected function InitSocket()
{
$this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("Failed: socket_create()");
socket_connect($this->socket, $this->addr, $this->port) or die("Failed: socket_connect()");
// Add it as the only client also
$client = call_user_func(array($this->clientSocket, getInstance), $this->socket, $this, $this->maxBufferSize);
array_push($this->clients, $client);
}
public function newClient()
{
return reset($this->clients); // return first
}
function removeClient($client)
{
}
public function getAllSockets()
{
$A = array();
array_push($A, $this->getListeningSocket());
return $A;
}
public function CallClients($func)
{
foreach ($this->clients as $client)
{
call_user_func(array($client, $func));
}
}
public function CallClients1($func, $v1)
{
foreach ($this->clients as $client)
{
call_user_func(array($client, $func), $v1);
}
}
public function CallClients4($func, $v1, $v2, $v3, $v4)
{
foreach ($this->clients as $client)
{
call_user_func(array($client, $func), $v1, $v2, $v3, $v4);
}
}
}
SetLogFile(dirname($argv[0]) . "/logfile.txt");
LogWrite("############################## Restarted ######################################");
$serverState = ServerState::getInstance();
//LogWrite($serverState->dump());
$LS1 = new LPECListeningSocket($LINN_HOST, $LINN_PORT, 'LPECClientSocket', $serverState, 30000);
$LS2 = new LinnDSListeningSocket(0, 9050, 'LinnDSClientSocket', $serverState, 30000);
$LS2->setLPECListeningSocket($LS1);
//$LS3 = new LinnDSwsListeningSocket(0, 9051, 'LinnDSClientSocket', $serverState, 30000);
//$LS3->setLPECListeningSocket($LS1);
//$LS1->dump();
//$LS2->dump();
//$LS3->dump();
$SS = new SocketServer();
$SS->addListeningSocket($LS1);
$SS->addListeningSocket($LS2);
//$SS->addListeningSocket($LS3);
LogWrite("LinnDS-jukebox-daemon starts...");
try {
$SS->run();
}
catch (Exception $e) {
LogWrite($e->getMessage());
}
?>