summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/web/socket2.php
blob: 475063a66ca9230bb48c4cae5c725fb4e44224ce (plain) (blame)
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
<?
 $ip = "localhost";
 $port = 34500;
 exec("/usr/bin/python /var/www/server1.py > /dev/null 2>&1 &");
// echo $result . '<br>'; 
// echo str_repeat("\n",7024);
// flush();

 sleep(2);

 $fp = fsockopen($ip, $port, $errno, $error, 5);

 if (!$fp)
 {
 	printf('ERROR');
 }
 else
 {
 	socket_set_timeout( $fp, 50); //one should set the number of the longest test, so we can define the timeout
    	fwrite($fp, "START TEST"); //send command to start the tests
    
    	if(!feof($fp)) 
	{
	   while(!feof($fp)) 
	   {
        	$received =  fgets($fp, 128);
		if ($received == "CONFIRM\n")
		{
			//echo 'CONFIRM CONNECTION <br>';
			echo '<table summary = "Submitted table designs"> 
			<caption> Table concept for our results </caption> 
			<thead> 
			<tr> 
			<th scope = "col"> From: </th> 
			<th scope = "col" > To: </th> 
			<th scope = "col"> Message: </th> 
			<th scope = "col"> Status: </th> 
			</tr> 
			</thead> 
			<!-- start of the table rows--> 
			<tbody>';
              		echo str_repeat("\n",7024);
              		flush();
		}
		elseif ($received == "TEST DONE\n")
		{
			echo '</tbody></table>';
			//echo 'DISCONNECT <br>';
              		echo str_repeat("\n",7024);
              		flush();
			usleep(100);
			fwrite($fp, 'DISCONNECT');
			break;
		}
		else
		{
			echo '<tr> 
<th scope = "row" id = "r100"> SIP</th> 
<th scope = "row" id = "r100">GSM1 </th> 
<td> '. $received . ' </td> 
<td> 200</td> 
</tr>';
			//echo $received . '<br>';
              		echo str_repeat("\n",7024);
              		flush();
			usleep(100);
			fwrite($fp, "CONTINUE");
		}
	   }
	}
 	fclose($fp);
 }
?>