-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.php
52 lines (47 loc) · 1.1 KB
/
server.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
<?php
require 'vendor/autoload.php';
require 'includes/config.php';
require 'includes/classes/Database.php';
require 'includes/classes/Chat.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
/**
* Create a new connection to
* the database that we can inject
* to our chat class later on in
* the code.
*/
if (ENABLE_DATABASE == true) {
$db = new Database(
DATABASE_USERNAME,
DATABASE_PASSWORD,
DATABASE_HOST,
DATABASE_PORT,
DATABASE_DB
);
} else {
$db = null;
}
/**
* Instantiate the chat server
* on the configured port in
* includes/config.php.
*
* The includes/classes/Chat.php class will
* handle all the events and database interactions.
*/
$server = IoServer::factory(
new HttpServer(
new WsServer(
new Chat($db) /* This class will handle the chats. It is located in includes/classes/Chat.php */
)
),
WEBSOCKET_SERVER_PORT,
WEBSOCKET_SERVER_IP
);
echo "Server running at ".WEBSOCKET_SERVER_IP.":".WEBSOCKET_SERVER_PORT."\n";
/**
* Run the server
*/
$server->run();