LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 03-18-2010, 11:48 AM   #1
Neethusha
LQ Newbie
 
Registered: Feb 2010
Posts: 16

Rep: Reputation: 0
Extension Server communication


How can an extension communicate with a server?
how do they exchange data?
suppose u sign in to a page, how does the connection between th
extension and server be after sign in?
how does the server send a message to one of these signed in clients?

i tried the communication part in ajax httprequest response
objects...the javascript n php are communicating...but wen i
integrated the code into the extension, it din give output.
i heard that ajax wont work well in the backend in xul
applications..something about xml render....is there any other way for
carrying out this extension server communication...

a Mozilla Firefox extension which connects two or more people located
at geographically distant areas, who happen to be browsing the same
website simultaneously. It shows you other people who visit the same
websites as you are.

The extension informs the server whenever the user clicks the
EnableChat button to start a chat session.
The server retrieves from its database, the list of users who are
currently online in that site and returns it.
The user can then click on any username for opening a chat session.
this is my xul file:

<?xml version="1.0"?>
<overlay id="blaze-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script language="javascript" type="text/javascript" src="chrome://
blaze/content/connect.js" />
<toolbox id="navigator-toolbox">
<toolbar id="blaze-toolbar" align="center" toolbarname="blaze"
accesskey="B" class="chromeclass-toolbar" context="toolbar-context-
menu" hidden="false" persist="hidden">
<label control="some-text" value="Username"/>
<textbox id="some-text"/>
<label control="some-password" value="Password" />
<textbox id="Userpassword" type="password" maxlength="15"
onkeypress="if(event.keyCode == 13)
{alert('good');verifyusernamepasswd();}"/>
<toolbarbutton id="blaze-button" tooltiptext="Click for chat with
other users"
label="Enable Chat" oncommand="getUsers('php.com');" />
<toolbarbutton id="blaze-logout" tooltiptext="Click to log out of
BLAZE" label="Logout" oncommand="alert('bye!')" />
</toolbar>
</toolbox>
<statusbar id="status-bar">
<statusbarpanel id="my-panel" label="Hello, World" />
</statusbar>
</overlay>


getUsers.js

var xmlhttp;
function getUsers(u)
{
alert('hi');
xmlhttp=new XMLHttpRequest();
var url="servercode.php?q="+u;
xmlhttp.onreadystatechange= useHttpResponse;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function useHttpResponse()
{
alert(xmlhttp.readyState);
if (xmlhttp.readyState==4 )
{
alert(xmlhttp.responseText);
}
}


verifyusernamepasswd():

var xml;
function verifyusernamepasswd()
{
var usernamebox=document.getElementById("some-text");
var passwordbox = document.getElementById("Userpassword");
var username=usernamebox.value;
var password=passwordbox.value;
alert(username);
xml=new XMLHttpRequest();
var url="loginvalidate.php";
var param="q="+username+"&p="+password;
xml.open("POST",url,true);
xml.setRequestHeader("Content-type", "application/x-www-form-
urlencoded");
xml.setRequestHeader("Content-length", param.length);
xml.setRequestHeader("Connection", "close");
xml.onreadystatechange=statechanged1();
xml.send(param);
}

function statechanged1()
{
if(xml.readyState==4 && xml.status==200)
alert(xml.responseText);
}


servercode.php

<?php
$q=$_GET["q"];
$con=mysql_connect("localhost","root","blaze");
if(!$con)
{die('could not connect to database'.mysql.error());
}

mysql_select_db("BLAZE",$con) or die("No such Db");
$result=mysql_query("SELECT * FROM USERURL WHERE url='php.com'");
if($result == null)
echo 'halla';
header('Content-type: text/html');
echo '{Users:[';
while($row=mysql_fetch_array($result))
{
echo"{UserId:".$row[UsrID]."},";
}

echo "]}";
mysql_close($con);
?>


loginvalidate.php:

<?php
$con = mysql_connect("localhost","root","blaze");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$username=$_POST['username'];
$password=$_POST['password'];
var $false="false";
var $true="true";
mysql_select_db("BLAZE",$con);
$result=mysql_query("SELECT Userid,Password FROM USERTABLE WHERE
Userid='$username'");
if($result==NULL)
echo $false;
else
{
$row=mysql_fetch_array($result)
if((strcmp($row["Userid"],$username)!=0)||(strcmp($row["Password"],
$password)!=0))
{
echo $false;
}

else
echo $true;
}

?>
my problem is that i cant get the response of the php to the
extension. there is proper connection between my javascript n
php...for eg, i ran the javascript in html in /var/wwww here server
code is n i got output. but wen i integrated it with the extension, i
din get the response from php to the extension...
what could possibly be wrong????????

Last edited by Neethusha; 03-18-2010 at 11:49 AM.
 
Old 03-18-2010, 05:38 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread

Tags
coming, presentation, project



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

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Firefox Extension: about communication with the server Neethusha Programming 4 03-18-2010 09:22 PM
Server Client communication Kakarot_Rathish Programming 7 01-09-2009 05:40 PM
Fault in KDE processes communication: Could not read network communication list Magnus Johansson MEPIS 0 03-30-2008 12:50 PM
server/browser communication calorie712 Programming 1 03-16-2006 05:24 PM
communication across a proxy server sureshk Linux - Networking 0 10-09-2003 01:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration