-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.php
39 lines (30 loc) · 1 KB
/
client.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
<?php
/*
* This script connects to the Python socket server as a client. This happens when a user clicks on a tool on the
* torture screen. It gets the message that is sent by a xmlhttprequest and sends this message to the socket
* server. It uses the localhost since the server runs on the same machine as the python tool script.
* Port was randomly chosen because you can use any port in the range of 1024-49151
*/
// Start the session
session_start();
// Check if the user is logged in, if not redirect him to the startpage
if(!$_SESSION['loggedin']){
header('Location: index.php');
die();
}
// Port
$service_port = 9997;
// Localhost
$address = '127.0.0.1';
// Create a TCP/IP socket
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
// Connect to the socket server
$result = socket_connect($socket, $address, $service_port);
// Get the message
$str = $_REQUEST["q"];
// Send a message
$length = strlen($str);
socket_write($socket, $str, $length);
// Close the socket
socket_close($socket);
?>