473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

javascript and server socket

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.nsIServerSock et);

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.nsIServerSock et);

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>

Feb 2 '06 #1
2 10073
giangiammy wrote:
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/>
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.
serverSocket =
Components.classes["@mozilla.org/network/server-socket;1"].
createInstance(Components.interfaces.nsIServerSock et);
This is script code, executed by the JavaScript engine.
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>
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.
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.
[invalid markup]


Learn HTML before you learn J(ava)Script/ECMAScript.

<URL:http://validator.w3.org/>
PointedEars
Feb 2 '06 #2
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!";
}

Feb 3 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
4
by: jas | last post by:
I have a basic client/server socket situation setup....where the server accepts a connection and then waits for commands. On the client side, I create a socket, connect to the server...then I...
3
by: ferbar | last post by:
Hello all, This may sound pretty basic stuff.. but I'm working on a socket example whose client seems to work fine, but the server doesn't send to the client the expected result. The problem is...
2
by: CHRISM | last post by:
Hiya, Been trying to figure this one out. I've written a very simple server in VB.NET that listens for client connections, then spits out a bunch of text and then closes the connection. Much...
3
by: O.B. | last post by:
When sharing a Socket between threads, are the socket operations automatically synchronized to support multithreading? For example: Thread1 sets up a server socket to listen and invokes...
1
by: Miroslav Endys | last post by:
I have two apps. Client and Server (both are windows console apps). Im using Client Socket of this definition AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp and Im using async...
0
by: cmrhema | last post by:
Hi, We have an asynchronous server socket program, which works fine BUT, when due to some circumstances, I receive null data or blank data, the server goes to infinite loop Here is the code ...
1
by: meenus | last post by:
dears, i downloaded one socket application fro recvng the data from different units(vehicle tracking system) .my pblm is sometimes some of the data is not getting in to the server socket which is...
0
by: ryaneoghan | last post by:
hi, I was just wondering if anyone could help, i am trying to create a client and server socket connection in perl, i want to ask for name and then do a check on the name and ask for a secret word...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.