|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Jslib socket program...Hello everyone,
I have just installed jslib on firefox 3.5. I want to do p2p communication using socket But as soon as me and my friend try to do socket communication by pressing open socket we get status as socket disconnected...
I have done some changes to it for continuously listening to socket, changes are as follows <?xml version="1.0"?> <!DOCTYPE window> <window id="jslib-socket-test" title="jslib Socket Test" style="background-color: #cccccc; width: 500px;" xmlns:html="http://www.w3.org/1999/xhtml" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" onload="initialize();" > <script type="application/x-javascript"> jslib.init(this); JS_LIB_DEBUG = true; jslibTurnDumpOn(); try { // enablePrivilege is required if not running chrome'd // (other tweaks might apply, check out public.mozdev.jslib) netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); include(jslib_socket); } catch( e ) { alert( e ); } var gSocket = new Socket; var hostElement; var portElement; var sendMsg; var socketResults; var statusMsg; function initialize() { hostElement = document.getElementById( "host" ); portElement = document.getElementById( "port" ); sendMsg = document.getElementById( "sendMsg" ); loading = document.getElementById( "loading" ); socketResults = document.getElementById( "socketResults" ); statusMsg = document.getElementById( "statusMsg" ); setInterval(function(){if( !gSocket.isConnected )loading.value="Not connected"; else loading.value="Connected";},100); } function closeSocket() { gSocket.close(); statusMsg.value = "socket was closed"; } function openSocket() { if( gSocket.isConnected ) return; var host = hostElement.value; var port = portElement.value; gSocket.open( host, port, true ); statusMsg.value = "an attempt was made to open the socket"; } function receiveSocket() { bytesAvailable = gSocket.available(); if( gSocket.isConnected ) { socketData = gSocket.read( bytesAvailable ); if(socketData.length!=0){ socketResults.value = "[" + socketData + "]\nLength: " + socketData.length; } } else { //socketResults.value = "the socket is closed"; } } function startReceiving(){ setInterval(receiveSocket,100); } function sendSocket() { theMsg = sendMsg.value; gSocket.write( theMsg+"\0" ); statusMsg.value = "sent [" + theMsg + "]"; } function testSocket() { statusMsg.value = ( gSocket.isAlive() ? "socket is connected" : "socket is not connected" ); } function availableSocket() { statusMsg.value = ( gSocket.isAlive() ? "socket has " + gSocket.available() + " bytes pending" : "socket is not connected" ); } </script> <hbox> <vbox flex="1"> <hbox> <label control="host" value="Host:"/> <textbox id="host" value="" /> </hbox> <hbox> <label control="port" value="Port:"/> <textbox id="port" value="3000" /> </hbox> <hbox> <label control="statusMsg" value="Status:"/> <textbox id="statusMsg" value="" flex="1" /> </hbox> <hbox> <label control="sendMsg" value="Send:"/> <textbox id="sendMsg" value="" flex="1" /> </hbox> <hbox> <label control="socketResults" value="Response:"/> <textbox id="socketResults" value="" flex="1" /> </hbox> <hbox> <label id="loading" value=""/> </hbox> </vbox> <vbox flex="0" > <spacer flex="1" /> <button label="Open" oncommand="openSocket();" /> <button label="Send" oncommand="sendSocket();" /> <button label="Receive" oncommand="startReceiving();" /> <button label="Connected?" oncommand="testSocket();" /> <button label="Available?" oncommand="availableSocket();" /> <button label="Close" oncommand="closeSocket();" /> <spacer flex="1" /> </vbox> </hbox> </window> host - 127.0.0.1
port - 3000 send- pressed open button pressed receive button //will start listening, I have modified the code pressed send button I get some garbage value as response
When me and my friend tried to do socket communication using our ip and port no 3000 (Port has already been forwarded --other program written in python works perfectly on port 3000) But as soon as we open the socket we get status as socket is disconnected... Do we need to firefox for permission to create sockets. If yes how should we tell it. Thanks for any help... _______________________________________________ Jslib mailing list Jslib@... https://www.mozdev.org/mailman/listinfo/jslib |
|
|
Re: Jslib socket program...Yea, the socket code is pretty old at this point.
I update jsLib based on when I need it updated. I'll gladly take a patch if you have one. Thanks --pete sunil sarolkar wrote: > Hello everyone, > I have just installed jslib on firefox 3.5. > > I want to do p2p communication using socket But as soon as me and my > friend try to do socket communication by pressing open socket we get > status as socket disconnected... > > I have done some changes to it for continuously listening to socket, > changes are as follows > > <?xml version="1.0"?> > > > <!DOCTYPE window> > > > <window id="jslib-socket-test" > > title="jslib Socket Test" > > style="background-color: #cccccc; width: 500px;" > > xmlns:html="http://www.w3.org/1999/xhtml" > > xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" > > onload="initialize();" > > > > > > <script type="application/x-javascript"> > > jslib.init(this); > > JS_LIB_DEBUG = true; > > jslibTurnDumpOn(); > > > try { > > // enablePrivilege is required if not running chrome'd > > // (other tweaks might apply, check out public.mozdev.jslib) > > > netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); > > include(jslib_socket); > > } > > catch( e ) { alert( e ); } > > > var gSocket = new Socket; > > var hostElement; > > var portElement; > > var sendMsg; > > var socketResults; > > var statusMsg; > > > function initialize() > > { > > hostElement = document.getElementById( "host" ); > > portElement = document.getElementById( "port" ); > > sendMsg = document.getElementById( "sendMsg" ); > > loading = document.getElementById( "loading" ); > > socketResults = document.getElementById( "socketResults" ); > > statusMsg = document.getElementById( "statusMsg" ); > > setInterval(function(){if( !gSocket.isConnected > )loading.value="Not connected"; else loading.value="Connected";},100); > > } > > > function closeSocket() > > { > > gSocket.close(); > > statusMsg.value = "socket was closed"; > > } > > > function openSocket() > > { > > if( gSocket.isConnected ) > > return; > > > var host = hostElement.value; > > > var port = portElement.value; > > > gSocket.open( host, port, true ); > > statusMsg.value = "an attempt was made to open the socket"; > > } > > > function receiveSocket() > > { > > bytesAvailable = gSocket.available(); > > if( gSocket.isConnected ) > > { > > socketData = gSocket.read( bytesAvailable ); > > if(socketData.length!=0){ > > socketResults.value = "[" + socketData + "]\nLength: " + > > socketData.length; > > } > > } > > else > > { > > //socketResults.value = "the socket is closed"; > > } > > } > > function startReceiving(){ > > setInterval(receiveSocket,100); > > > > } > > function sendSocket() > > { > > theMsg = sendMsg.value; > > gSocket.write( theMsg+"\0" ); > > statusMsg.value = "sent [" + theMsg + "]"; > > } > > > function testSocket() > > { > > statusMsg.value = ( gSocket.isAlive() > > ? "socket is connected" > > : "socket is not connected" ); > > } > > > function availableSocket() > > { > > statusMsg.value = ( gSocket.isAlive() > > ? "socket has " + gSocket.available() + " bytes pending" > > : "socket is not connected" ); > > } > > </script> > > > <hbox> > > <vbox flex="1"> > > <hbox> > > > <label control="host" value="Host:"/> > > <textbox id="host" value="" /> > > </hbox> > > <hbox> > > <label control="port" value="Port:"/> > > <textbox id="port" value="3000" /> > > </hbox> > > <hbox> > > <label control="statusMsg" value="Status:"/> > > > <textbox id="statusMsg" value="" flex="1" /> > > </hbox> > > <hbox> > > <label control="sendMsg" value="Send:"/> > > <textbox id="sendMsg" value="" flex="1" /> > > </hbox> > > <hbox> > > <label control="socketResults" value="Response:"/> > > <textbox id="socketResults" value="" flex="1" /> > > > </hbox> > > <hbox> > > <label id="loading" value=""/> > > </hbox> > > </vbox> > > > > <vbox flex="0" > > > <spacer flex="1" /> > > <button label="Open" oncommand="openSocket();" /> > > <button label="Send" oncommand="sendSocket();" /> > > <button label="Receive" oncommand="startReceiving();" /> > > <button label="Connected?" oncommand="testSocket();" /> > > <button label="Available?" oncommand="availableSocket();" /> > > > <button label="Close" oncommand="closeSocket();" /> > > <spacer flex="1" /> > > </vbox> > > </hbox> > > </window> > > > > host - 1 <http://google.com>27.0.0.1 > port - 3000 > send- > pressed open button > pressed receive button //will start listening, I have modified the code > pressed send button > I get some garbage value as response > > When me and my friend tried to do socket communication using our ip > and port no 3000 > (Port has already been forwarded --other program written in python > works perfectly on port 3000) > > But as soon as we open the socket we get status as socket is > disconnected... > > > Do we need to firefox for permission to create sockets. If yes how > should we tell it. > > Thanks for any help... > > ------------------------------------------------------------------------ > > _______________________________________________ > Jslib mailing list > Jslib@... > https://www.mozdev.org/mailman/listinfo/jslib > -- Pete Collins - Founder, Mozdev Group Inc. www.mozdevgroup.com Mozilla Software Development Solutions tel: 1-719-302-5811 fax: 1-719-302-5813 _______________________________________________ Jslib mailing list Jslib@... https://www.mozdev.org/mailman/listinfo/jslib |
| Free embeddable forum powered by Nabble | Forum Help |