My Ideas

Home


view:  full / summary

Communication between python socket server and as3.0 xmlsocketserver

Posted by Seema Navale on January 14, 2011 at 1:18 AM Comments comments (0)

Hi,

I found that there were initally problems reagarding communication  with python socket server and as3.0 xmlsocket server .Hence  am just showin some simple way to do that .


Python socketserver code:

import socket

import sys


conn, addr = s.accept()

s = "localhost"

for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,

                              socket.SOCK_STREAM, 0, socket.AI_PASSIVE):

    af, socktype, proto, canonname, sa = res

    try:(

        s =( socket.socket(af, socktype, proto)

    except socket.error, msg:

        s = None

        continue

    try:

        s.bind(sa)

        s.listen(1)

    except socket.error, msg:

        s.close()

        s = None

        continue

    break

if s is None:

    print 'could not open socket'

    sys.exit(1)

    

conn, addr = s.accept()

print 'Connected by', addr

data=conn.recv(1024)

print data

conn.send(data)

    

conn.close()




As3.0 code:


import flash.events.*;

import flash.net.XMLSocket;

var hostName:String = "localhost";

var port:uint = 8087;

 var socket:XMLSocket;

 

socket = new XMLSocket();

socket.connect(hostName, port);


socket.addEventListener(Event.CONNECT,xmlsocket);

socket.addEventListener(Event.CLOSE,xmlsocket);

socket.addEventListener(IOErrorEvent.IO_ERROR,xmlsocket);

socket.addEventListener(DataEvent.DATA, xmlsocket);

socket.send("Message here");


function xmlsocket(Event):void {

    switch (Event.type) {

        case 'ioError' :

            //Unable to Connect

            trace("Error");

            break;

        case 'connect' :

               trace("i got connected");

        

            //Connected

            break;

         

        case 'close' :

        trace("disconnected");

        

            //OnDisconnect

            break;

        default:

   

        trace(Event.data);

        socket.send("ya got");

        

        break;

        

    }

}

 

 






//run python socket server which will be listening to port 8087

//Then run as3.0 server and finally communication happens.

//as3.0 server sends a message here and python server receives it and prints

//it and sends got message back to as3.0 server (python server quits after this )

//and finally as3.0 prints and gets disconnected(this works fine for localhost)

//but when cross domain is involved crossdomainpolicy file comes into picture

//that has to be taken care.


output: (on as3.0)

i got connected

Message here

disconnected



output:(on python server)

>>>

Connected by ('127.0.0.1', 3852)

Message here



 

 


                                                                                                                                                                Happy Coding

 

 



steps to run a python program from command line(XP)

Posted by Seema Navale on January 3, 2011 at 6:39 AM Comments comments (0)


 I would like to initally state the problem that i faced while running the python scripts from command line in XP.


>>> python hello.py

SyntaxError: invalid syntax

Solution:

The reason for the error is am already running the interpreter and again trying to call one

So just type exit()

and you will return to C:\python27\ in my case


and type python hello.py


It works fine....

And also take care that you move to  directory where ptyhon is.And also set this path in environment variables.


                                                                                                                                                                   Happy Coding

HelloWorld program in as3.0 using Flash CS5

Posted by Seema Navale on January 3, 2011 at 1:54 AM Comments comments (0)


Hi after strugling for so many days of executing as3.0 in CS5 finally found the solution in one blog.

Steps:

Download a Flash CS5 trial verion


1>Open Flash Pro CS5 ,in that goto File->New->Actionscript 3.0 class


type->class:MyHelloWorld


type the folowing code :

package{

public class MyHelloworld{

public function MyHelloWorld(){

//constructor code

}

public function sayHello(){

var greeting:String="Hello World";

return greeting;

}


}

}



3>Save as MyHelloWorld.as

4>File->New->Actionscript 3.0

Click T in the right  menu bar

draw a rectangle at the center of the stage


change the <instance name> in T ,in the right panel as hello_txt


4>press F9  to get actions panel

type the following code:

import MyHelloWorld;

var classInstance:MyHelloWorld=new MyHelloWorld();

hello_txt.text=classInstance.sayHello();


5>Save as MyHelloWorld.fla


6>Control->Test Movie  in flash pro cs5

you can watch a swf file


7>File->Export->Export Movie

save as MyHelloWorld.swf


8>output:






                                                                                        Hello World







                                                                                                                            Happy Coding


How to display flot examples in IE6+ (Solution)

Posted by Seema Navale on November 25, 2010 at 12:41 AM Comments comments (0)

Soln to use flot lib in IE..

Well ,the only best solution i found was to use the latest excanvas.min.js ,in which they have debugged this error.

And all flot examples can be comfortably run now .No more errors.

                                                                                                          

                                                                                                                                               Happy Coding

To call a sleep function in javascript using setTimeout()

Posted by Seema Navale on October 25, 2010 at 1:23 AM Comments comments (0)

Sample program:

It writes using document.write msg and calls alert after 3s hello msg and later hel msg


CODE:

document.write("First");

var int=self.setTimeout("timer('hello')",3000);

function timer(msg)

{

alert(msg);

}

var a="hel"

var int=self.setTimeout("timer(a)",3000);



//setTimeout() is used to call the function only once and to call it at regular //intervals //setInterval(code,millisec,lang)


Hope this will be a bit of help to implement sleep () in javascript....



                                                                                                                           HAPPY CODING

                                       


Deploy servlets on tomcat server

Posted by Seema Navale on May 10, 2010 at 12:58 PM Comments comments (0)


Steps to run servlets using Tomcat server 5.0 on XP:



  • create a folder called servlet or any name in tomcat's webapps directory
  • In that  directory say servlet create a WEB-INF folder .
  • Within WEB_INF create classes folder,this is the folder where you are supposed to keep your compiled .class files
  • Then go to root folder in webapps copy  web.xml in that directory to servlet/WEB-INF/ directory  and to your reference am  showing web.xml in my tomcat version,it varies please do copy it from your tomcats ROOT folder itself.
  • I will show which fields need to be manipulated in it
  • change servlet name to your servlet name and class name to class name that is created

 

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app

    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

  <display-name>Welcome to Tomcat</display-name>

  <description>

     Welcome to Tomcat

  </description>

<!-- JSPC servlet mappings start -->

    <servlet>

        <servlet-name>hello</servlet-name>

        <servlet-class>hello</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>hello</servlet-name>

        <url-pattern>/hello</url-pattern>

    </servlet-mapping>

<!-- JSPC servlet mappings end -->

</web-app>








As shown in above  web.xml file i just changed servlet-name to hello and class-nameto hello between the tags as shown above



Then start your tomcat server and give the path in my case i gave path to be

http://localhost:8080/servlet/hello


And congrates you have executed your first servlet program


 If you want to acces database mysql as such add connectors in  servlet/WEB-INF/lib directory by explicitly creating that directory and carry on

                                                                                                            Enjoy Servlets

Servlet Setup

Posted by Seema Navale on May 6, 2010 at 3:04 PM Comments comments (0)

            SETUP NEEDED TO EXECUTE SERVLETS USING COMMAND LINE TOMCAT 5.0

 

Step1:It depends on the web server which you are using wherethe servlet.jar or servlet-api.jar. In my case it was in 

C:\Program Files\ApacheSoftware Foundation\Tomcat 5.0\common\lib\servlet-api.jar.

 

Step 2:

Setting as a classpath asshown in snapshots goto->mycomputer->rt click->Advancedproperties->environment variables

 

 

 

Step3:Take care that you set the classpath properly.And sometimes check your code if you get errors don’t jump to the conclusion that path is not set .

 

Step5:Finally command to beused in command line to execute servlet

Program

C:>javac-classpath ".;C:\Program Files\Apache Software Foundation\Tomcat5.0\common\lib\servlet-api.jar" hello.java

 

A class file will get created.

Examplesample servlet code:A program to display hello save it as hello.java

 


import java.io.*;

import java.text.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class hello extends HttpServlet {

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("");

out.println("");

out.println("hello");

out.println("");

out.println("");

}

}


                                                                    Enjoy  Servlets



*To find out how to run servlets using tomcat checkout my tutorial on Deploying in Tomcat server



                                                                                    

                                                                                            

 


 

 


Rss_feed