|
|
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
|
|
comments (0)
|
>>> python hello.py
SyntaxError: invalid syntax
|
|
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
|
|
comments (0)
|
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
|
|
comments (0)
|
Sample program:
It writes using document.write msg and calls alert after 3s hello msg and later hel msg
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
|
|
comments (0)
|
Steps to run servlets using Tomcat server 5.0 on XP:
<?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
|
|
comments (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