Forum Discussion
Altera_Forum
Honored Contributor
14 years agoon line 1053:
void send_dbcount(http_conn* conn)
{
alt_u8* tx_wr_pos = conn->tx_buffer;
alt_u8* dbcounter_str = (alt_u8*) malloc(512);
alt_u8* dbcounter_str_pos = dbcounter_str;
unsignedint content_length;
int result;
// Send the version string.
tx_wr_pos += sprintf( tx_wr_pos, HTTP_VERSION_STRING );
// Send the HTTP_OK header element.
tx_wr_pos += sprintf( tx_wr_pos, HTTP_OK_STRING );
// Send the content type header element.
tx_wr_pos += sprintf( tx_wr_pos, HTTP_CONTENT_TYPE_JS );
// Add the cache content header element.
tx_wr_pos += sprintf( tx_wr_pos, "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n" );
// Now build the content string and determine it's length. This content is in JSON (Javascript Object Notation)
// and is easily handled by any browser that understands Javascript.
dbcounter_str_pos += sprintf( dbcounter_str, "new Object ({ 'count' : '%d'})\r\n",dbcount.dbcounter);
content_length = strlen( dbcounter_str );
// Add the Content-Length header element.
tx_wr_pos += sprintf( tx_wr_pos, HTTP_CONTENT_LENGTH );
tx_wr_pos += sprintf( tx_wr_pos, "%d\r\n", content_length );
// Since the connection will be closed after sending this packet, add the HTTP_CLOSE header element
// and mark the end of headers by sending HTTP_CR_LF.
tx_wr_pos += sprintf( tx_wr_pos, HTTP_CLOSE );
tx_wr_pos += sprintf( tx_wr_pos, HTTP_CR_LF );
// Now, add in the progress_str content (actual content for a 'GET /PROGRESS' request.
tx_wr_pos += sprintf( tx_wr_pos, "%s", dbcounter_str );
// Send the reply packet.
result = send( conn->fd, conn->tx_buffer, (tx_wr_pos - conn->tx_buffer), 0 );
if (result < 0)
{
fprintf( stderr, " header send returned %d\n", result );
conn->
state = RESET;
return;
}
free( dbcounter_str );
}
but what do the function on line 1905 ?
int http_handle_get( http_conn* conn )
{
int ret_code = 0;
if ( !strcmp( conn->uri, progress_field.name ))
{
conn->state = CLOSE;
progress_field.
func( conn );
}
else
{
// Find file from uri
ret_code = http_find_file( conn );
}
return ret_code;
}
and how can i edit them to display more then one data on the website ? I have edit the website.h likes this: (on line 199)
void send_dbcount( http_conn* conn );
and the Javascript file show jet so:
interval_msec = 2000;
debug = false;
function update() {
// Handle the various browsers... Pre-IE7 doesn't support XMLHttpRequest.
if (window.XMLHttpRequest && !(window.ActiveXObject)) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// IE/Windows ActiveX
} else if (window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
// If request isn't possible, just return right away.
if (!req) return;
req.open("GET","/DBCOUNT", false);
req.send(null);
if(req.status == 200) {
// The server sent a response.
var dbcount = eval(req.responseText);
if(debug) {
document.getElementById('debug_panel').innerHTML += "counter = " + dbcount.dbcounter + " " + '<br />';
}
bar = document.getElementById('dbcounter');
w = (dbcount.counter/100) * 180;
bar.style.width = w + 'px';
document.getElementById('tp').innerHTML = progress.percent + "%";
}
else {
// Something didn't work....at least set an alert with useful information!
alert("Error " + request.status + ": " + request.statusText );
}
}
function startProgress() {
// Code needs to go here to generate the progress bar.
interval = window.setInterval(
function () {
update();
},
interval_msec
);
};
the last file i have edit is the HTML index file and they show like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Nios II Example Web Server</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="dbcounter.js"></script>
</head>
<body>
<div id="dbcount" style="width: 200px; border 1px solid black">
<div id="dbcounter" style="width: 0px; height: 1.5ex; background-color: black; border: 0px solid white; margin-left: 0.5em; margin-right: 0.5em; margin-top: 1ex">
</div>
</body>
</html>
have anybody i idea ?