-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfo.php
More file actions
executable file
·116 lines (94 loc) · 3.56 KB
/
Info.php
File metadata and controls
executable file
·116 lines (94 loc) · 3.56 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!-- LOG
Instruction of the RabbitMQ 2015.03.29 Pingjiang
Each client has same function: send and receive messages.
This webpage used to receive the messages and display the information.
You can use the function like that:
client.connect(login, passcode, function(frame) {
client.subscribe(destination, function(message) {
if(message.headers.type!='keep_alive')
{
//write your code here
//tell whether is your message by checking the 'type' value in headers,
//for example your message type is 'abc'
if(message.headers.type!='abc')
{
//how to process
//the data is in message.body
//for example you want to display the data on the screen
$("#messages").append("<p>" + message.body + "</p>\n");
}
}
});
});
To send the message, you can use the function in default.php
here is a brief introduction about how to send message, for exaple the type is "test", the data is "I can use RabbitMQ now.":
client.send(destination, {type:'test'}, 'I can use RabbitMQ now.');//you can use the below method if you don't know what is destination
But in default.php, i create a simple method for you. also you can see the example.
RabbitMQ_send(message_type,message)
for example you can call the function like:
RabbitMQ_send('test',I can use RabbitMQ now.)
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>MAP INFO</title>
</head>
<body background="images/stucco.png">
<div class="container-fluid">
<div class="row-fluid">
<div class="span6">
<div class="page-header">
<h2 align="center">Ubi Traffic</h2>
</div>
<div id="messages">
</div>
</div>
<div class="span4" style="display:none">
<div class="page-header">
<h2>Debug Log</h2>
</div>
<pre id="debug"></pre>
</div>
</div>
</div>
<!-- Scripts placed at the end of the document so the pages load faster -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="stomp.js"></script>
<script>
$(document).ready(function() {
var client, destination;
var url = 'ws://bunny.ubioulu.fi:15674/stomp/websocket';
var login = 'ubitraffic';
var passcode = '2iUn1oX3q4v35rP';
var ipAddress = "<?php echo $_SERVER['REMOTE_ADDR'];?>";
destination = '/exchange/ubitraffic';
client = Stomp.client(url);
// this allows to display debug logs directly on the web page
client.debug = function(str) {
$("#debug").append(str + "\n");
};
// the client is notified when it is connected to the server.
client.connect(login, passcode, function(frame) {
client.subscribe(destination, function(message) {
//call-back function after receive new message can process here
if(message.headers.type!='keep_alive')// if is not keep connection message
{
if(message.headers.type=='html')
{
if(message.headers.ip==ipAddress)
$("#messages").html("<p>" + message.body + "</p>\n");
}
}
});
});
//This function is Very Important. Can not be removed.
//The RabbitMQ server will disconnect in less that 3 second.
//This function send message to keep connecting.
setInterval(function(){
client.send(destination, {type:'keep_alive'}, 'client is alive');
},1000);
});
</script>
</body>
</html>