-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforza.php
More file actions
47 lines (32 loc) · 1.17 KB
/
forza.php
File metadata and controls
47 lines (32 loc) · 1.17 KB
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
<?php
require "ForzaDataParser.php";
//Reduce errors
error_reporting(~E_WARNING);
//Create a UDP socket
if (!($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP))) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Couldn't create socket: [$errorcode] $errormsg \n");
}
echo "Socket created \n";
// Bind the source address
if (!socket_bind($sock, "0.0.0.0", 20127)) {
$errorcode = socket_last_error();
$errormsg = socket_strerror($errorcode);
die("Could not bind socket : [$errorcode] $errormsg \n");
}
echo "Socket bind OK \n";
file_put_contents("forza.csv", ForzaDataParser::csv_header());
//Do some communication, this loop can handle multiple clients
while (1) {
//echo "Waiting for data ... \n";
//Receive some data
$r = socket_recvfrom($sock, $buf, 1024, 0, $remote_ip, $remote_port);
echo "$remote_ip : $remote_port\n";
$fdp = new ForzaDataParser($buf, 'fh4');
file_put_contents("forza.csv", $fdp->to_csv(), FILE_APPEND);
//print_r($fdp->to_list());
//Send back the data to the client
// socket_sendto($sock, "OK " . $buf , 100 , 0 , $remote_ip , $remote_port);
}
socket_close($sock);