G
giangiammy
hi all,
I'd like to implement a server socket in java: something linke the
following example.
The problem is that the HTML has not the permission to execute
instruction
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSocket);
Question:
1 - how do I give it this permisison?
2 - one solution I thought was to put the javascript code in a firefox
extension, to load, so it should have all needed permisison, but,
How can I call a java script function define in an extension
from an html page? - there's some particular syntax?
thanks
giammy
<<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
var serverSocket;
function start()
{
var listener =
{
onSocketAccepted : function(socket, transport)
{
try {
var outputString = "HTTP/1.1 200 OK\n" +
"Content-type: text/plain\n\n" +
"Hello there " + transport.host + "\n";
var stream = transport.openOutputStream(0,0,0);
stream.write(outputString,outputString.length);
stream.close();
} catch(ex2){ dump("::"+ex2); }
},
onStopListening : function(socket, status){}
};
try {
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSocket);
document.getElementById("log1").value = "got class";
serverSocket.init(7055,false,-1);
document.getElementById("log2").value = "got init";
serverSocket.asyncListen(listener);
document.getElementById("log3").value = "got listener";
} catch(ex){ dump(ex); document.getElementById("log9").value = ex; }
document.getElementById("status").value = "Started!";
}
function stop()
{
if (serverSocket) serverSocket.close();
document.getElementById("status").value = "Stopped!";
}
</script>
</head>
<body>
Verifica apertura socket:
<br>
<form>
<input id="b1" type="button" value="Start" onclick="start();">
<input id="b2" type="button" value="Stop" onclick="stop();">
Status: <input id="status" type="text" value="STOPPED">
<p>
<br><input id="log1" type="text" value="">
<br><input id="log2" type="text" value="">
<br><input id="log3" type="text" value="">
<br><input id="log4" type="text" value="">
<br><input id="log5" type="text" value="">
<br><input id="log6" type="text" value="">
<br><input id="log7" type="text" value="">
<br><input id="log8" type="text" value="">
<br><input id="log9" type="text" value="">
</form>
<br>
<br>
</body>
</html>
I'd like to implement a server socket in java: something linke the
following example.
The problem is that the HTML has not the permission to execute
instruction
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSocket);
Question:
1 - how do I give it this permisison?
2 - one solution I thought was to put the javascript code in a firefox
extension, to load, so it should have all needed permisison, but,
How can I call a java script function define in an extension
from an html page? - there's some particular syntax?
thanks
giammy
<<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
var serverSocket;
function start()
{
var listener =
{
onSocketAccepted : function(socket, transport)
{
try {
var outputString = "HTTP/1.1 200 OK\n" +
"Content-type: text/plain\n\n" +
"Hello there " + transport.host + "\n";
var stream = transport.openOutputStream(0,0,0);
stream.write(outputString,outputString.length);
stream.close();
} catch(ex2){ dump("::"+ex2); }
},
onStopListening : function(socket, status){}
};
try {
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSocket);
document.getElementById("log1").value = "got class";
serverSocket.init(7055,false,-1);
document.getElementById("log2").value = "got init";
serverSocket.asyncListen(listener);
document.getElementById("log3").value = "got listener";
} catch(ex){ dump(ex); document.getElementById("log9").value = ex; }
document.getElementById("status").value = "Started!";
}
function stop()
{
if (serverSocket) serverSocket.close();
document.getElementById("status").value = "Stopped!";
}
</script>
</head>
<body>
Verifica apertura socket:
<br>
<form>
<input id="b1" type="button" value="Start" onclick="start();">
<input id="b2" type="button" value="Stop" onclick="stop();">
Status: <input id="status" type="text" value="STOPPED">
<p>
<br><input id="log1" type="text" value="">
<br><input id="log2" type="text" value="">
<br><input id="log3" type="text" value="">
<br><input id="log4" type="text" value="">
<br><input id="log5" type="text" value="">
<br><input id="log6" type="text" value="">
<br><input id="log7" type="text" value="">
<br><input id="log8" type="text" value="">
<br><input id="log9" type="text" value="">
</form>
<br>
<br>
</body>
</html>