function websocket() { $websocket = array(); $websocket['socket'] = array(); $websocket['status'] = array(WEBSOCKET_NEW); $websocket['buf'] = array(""); websocket_set_address($websocket, "0.0.0.0"); websocket_set_port($websocket, 1234); websocket_set_message_limit($websocket, 1000); websocket_on_client($websocket, function ($ws, $client) { }); websocket_on_message($websocket, function ($ws, $client, $data) { }); websocket_on_close($websocket, function ($ws, $client) { }); return $websocket; }
if (isset($_REQUEST) && isset($_REQUEST['port'])) { $port = (int) $_REQUEST['port']; } } // ============================================================================= $database = pg_connect("dbname=cadist3d_db user=cadist3d"); pg_set_error_verbosity($database, PGSQL_ERRORS_VERBOSE); // ============================================================================= // get algorithm weights from database use_algorithm_weights(get_algorithm_weights()); // ============================================================================= $websocket = websocket(); websocket_set_port($websocket, $port); websocket_set_message_limit($websocket, $maxMessageSize); websocket_on_client($websocket, 'handle_client'); websocket_on_message($websocket, 'handle_message'); websocket_on_close($websocket, 'handle_close'); console("===\nServer started on port {$port}\n\n"); websocket_run($websocket); if (isset($websocket['error'])) { console("=## Error: " . $websocket['error']); } pg_close($database); console("==="); $console_enabled = TRUE; console("Server terminated"); // ============================================================================= $client_names = array(); $client_numbers = array(); function set_client($number, $name) {