HighDots Forums  

Re: javascript and server socket

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: javascript and server socket in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Thomas 'PointedEars' Lahn
 
Posts: n/a

Default Re: javascript and server socket - 02-02-2006 , 10:01 AM






giangiammy wrote:

Quote:
I'd like to implement a server socket in java:
Java or JavaScript? Because they have only the first four letters in
common. <URL:http://jibbering.com/faq/>

Quote:
something linke the following example.

The problem is that the HTML has not the permission to execute
instruction
HTML does not execute anything. It is a _markup_ language.

Quote:
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSock et);
This is script code, executed by the JavaScript engine.

Quote:
Question:
1 - how do I give it this permisison?
The script can request permission, and it can (not: must) be given by the
user:

<URL:http://developer.mozilla.org/en/docs/Bypassing_Security_Restrictions_and_Signing_Code>

Quote:
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
^^^^^^^^^^^
Again, the language is named "JavaScript" for a reason.

Quote:
from an html page? - there's some particular syntax?
[...]
AFAIK, you cannot. If you could, this would allow any foreign Web site
to trigger your extensions which do not run in the sandbox like the
client-side script code of the Web site. Surely you do not want that
to happen.

Quote:
[invalid markup]
Learn HTML before you learn J(ava)Script/ECMAScript.

<URL:http://validator.w3.org/>


PointedEars


Reply With Quote
  #2  
Old   
giangiammy
 
Posts: n/a

Default Re: javascript and server socket - 02-03-2006 , 11:32 AM






hi all,

I made some progress implementing the server socket using
javascript:

I wrote some code: it opens the socket, but I get the error
"Permission denied to get property UnnamedClass.host"
in the shown line, when I try to connect.
I think I need some instruction like:
netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
(but this is not working: any idea what privilege I need to
give?)

thanks again
giammy

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";


// THIS FUNCTION FAIL FOR PERMISSION PROBLEMS
var stream = transport.openOutputStream(0,0,0);

stream.write(outputString,outputString.length);
stream.close();
} catch(ex2){ dump("::"+ex2); }
},

onStopListening : function(socket, status){}
};

try {


netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");


serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSock et);
serverSocket.init(7055,false,-1);
serverSocket.asyncListen(listener);
} catch(ex){ dump(ex); }

document.getElementById("status").value = "Started!";
}

function stop()
{
if (serverSocket) serverSocket.close();
document.getElementById("status").value = "Stopped!";
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.