Re: Euphoria CGI

new topic     » goto parent     » topic index » view thread      » older message » newer message
jmduro said...

Maybe it's what you're thinking of: I intended to use Javascript to fire events (sending home-made UDP event frames to client side) as described here: https://www.w3schools.com/tags/ev_onmouseup.asp

It looks to me that HTML5 events are equivalent but I don't know how to handle them on client side. I need events to be catched by the OEU client that drives the browser, not by the browser itself.

Here is what I'm experimenting:

  • a standard web server with a CGI module (I use lighttpd)
  • a small notifier in OE run via CGI
  • main OE program acting as a server to get notifications via the CGI module

Create an HTML file with this javascript function

function sendNotification(url, params) { 
	var http = new XMLHttpRequest(); 
	http.open("POST", url, true); 
	//Send the proper header information along with the request 
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	http.send(params); 
} 

For each widget requiring action, as a button, call the method as in this example

<button onclick="sendNotification('notify.ex', 'action=delete&id=myButton')" class="btn btn-danger"> 
	<span class="glyphicon glyphicon-trash" title="Delete" aria-hidden="true"></span> 
</button> 

When button is clicked, there is an XMLHttpRequest towards the CGI module which relays notification to the main programs listening socket, so the main program can modify the HTML web page.

The CGI program relaying notifications is very short

include std/convert.e 
include std/io.e 
include std/socket.e as sock 
 
sequence cmd, query  
object nBytes 
 
cmd = command_line()  
nBytes = getenv("CONTENT_LENGTH") 
query = get_bytes(0, to_number(nBytes)) 
sock:socket sock = sock:create(sock:AF_INET, sock:SOCK_STREAM, 0) 
if sock:connect(sock, "127.0.0.1:5000") != sock:OK then 
	printf(1, "Could not connect to server, is it running?\nError = %d\n",  
		{ sock:error_code() }) 
	abort(1) 
end if 
sock:send(sock, query & "\n", 0) 
sock:close(sock) 

Main program listens on port 5000 in this example and gets notified when the button is clicked on the HTML page so it can update the file.

Regards

Jean-Marc

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu