Removing Multiple White-spaces from a string

A simple program to remove an arbitrary number of white spaces in between words. Program as follows:




//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include<iostream>
#include<string>

using namespace
std;

bool
removeDoubleSpaces(string& s)
{

bool
found = true;

int
i = s.find(" "); //Search for 2 spaces
if(i != string::npos)
{

s.replace(i, 2, " ");
}

else

found = false;

return
found;
}


string removeMultipleSpaces(const string& s)
{

string newStr(s);
bool
found = true;

while
(found)
{

found = removeDoubleSpaces(newStr);
}


return
newStr;
}


int
main()
{

string aString("This string has multiple spaces problem!");

cout<<"Original : "<<aString<<endl;
cout<<"Modified : "<<removeMultipleSpaces(aString)<<endl;

return
0;
}




The output is as follows:

How to create a Java CRUD Application With PostgreSQL and Postgres Plus sing JBoss SEAM (Java Server Faces, EJBs, and Hibernate) - J2EE Video Tutorial

http://www.youtube.com/watch?v=wL7njuFFnA4endofvid [starttext] This is a Video Tutorial explains This video shows a quick example of creating a working CRUD application on top of Postgres using JBoss SEAM (Java Server Faces, EJBs, and Hibernate). In 5 minutes, Jim Mlodgenski (Chief Architect, EnterpriseDB Corporation) uses the SEAM framework to build a basic application including reverse engineering the database schema to create boiler plate code for basic viewing and updating data.
[endtext]

61 - Java Programming Tutorial - Simple Polymorphic Program [polymorphism] - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=6d0m_L8_1XUendofvid [starttext] This is a Video Tutorial explains Simple Polymorphic Program
[endtext]

62 - Java Programming Tutorial - How to use JButton - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=6iV-v_m0z0wendofvid [starttext] This is a Video Tutorial explains How to use JButton
[endtext]

63 - Java Programming Tutorial - JButton Final Program - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=3RQOikbGGUMendofvid [starttext] This is a Video Tutorial explains
[endtext]

64 - Java Programming Tutorial - How to use JCheckBox - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=_UuDuj-RNRgendofvid [starttext] This is a Video Tutorial explains How to use JCheckBox
[endtext]

65 - Java Programming Tutorial - The Final Check Box Program - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=Y8zKDsenQFAendofvid [starttext] This is a Video Tutorial explains The Final Check Box Program
[endtext]

66 - Java Programming Tutorial - How to use JRadioButton - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=_d4CU9MveLEendofvid [starttext] This is a Video Tutorial explains How to use JRadioButton in java
[endtext]

67 - Java Programming Tutorial - JRadioButton Final Program - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=-ptlsT9KsM8endofvid [starttext] This is a Video Tutorial explains We finish out program to test radio buttons in java.
[endtext]

68 - Java Programming Tutorial - How to use JComboBox - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=vd-k2oBMXUIendofvid [starttext] This is a Video Tutorial explains How to use JComboBox in JAVA
[endtext]

69 - Java Programming Tutorial - How to make a program using drop down boxes - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=XS4-5GmRnp8endofvid [starttext] This is a Video Tutorial explains how to make a program using drop down boxes in JAVA
[endtext]

70 - Java Programming Tutorial - How to use a basic JList - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=GBlKa8cNROMendofvid [starttext] This is a Video Tutorial explains How to use a basic JList
[endtext]

71 - Java Programming Tutorial - How to use JList in JAVA - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=aLkkYbHz16Eendofvid [starttext] This is a Video Tutorial explains How to use JList in JAVA

[endtext]

72 - Java Programming Tutorial - How to select mutiple item in list - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=9z_8yEv7nIcendofvid [starttext] This is a Video Tutorial explains select multiple things in JAVA
[endtext]

73 - Java Programming Tutorial - How to Move List Items Program - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=68X8RUxeXeAendofvid [starttext] This is a Video Tutorial explains Moving List Items Program in JAVA

[endtext]

74 - Java Programming Tutorial - How to Responding to user mouse events - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=hsHqhX0s7Rsendofvid [starttext] This is a Video Tutorial explains Responding to user mouse events in JAVA

[endtext]

75 - Java Programming Tutorial - How to implement the methods in MouseListener interface - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=MpIHF4V3zMcendofvid [starttext] This is a Video Tutorial explains How to implement the methods in MouseListener interface
[endtext]

76 - Java Programming Tutorial - MouseMotionListener interface methods - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=sdUJR_DSyBUendofvid [starttext] This is a Video Tutorial explains MouseMotionListener interface methods
[endtext]

77 - Java Programming Tutorial - How to use an adapter class.- [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=UuKNGMCfSkQendofvid [starttext] This is a Video Tutorial explains how to use an adapter class in JAVA

[endtext]

78 - Java Programming Tutorial - How the file class can get info about files - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=7fC9nL3_AQQendofvid [starttext] This is a Video Tutorial explains How the file class can get info about files in JAVA

[endtext]

79 - Java Programming Tutorial - How to create a text file in java. - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=G0DfmD0KKycendofvid [starttext] This is a Video Tutorial explains How to create a txt file easily in java.
[endtext]

80 - Java Programming Tutorial - How to write data from a file - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=Bws9aQuAcdgendofvid [starttext] This is a Video Tutorial explains How to write data from a file in JAVA

[endtext]

81 - Java Programming Tutorial - How to read data from a file - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=3RNYUKxAgmwendofvid [starttext] This is a Video Tutorial explains How to read data from a file in JAVA

[endtext]

82 - Java Programming Tutorial - Exception Handling - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=K_-3OLkXkzYendofvid [starttext] This is a Video Tutorial explains Exceptions and errors are the exact same thing.
[endtext]

83 - Java Programming Tutorial - How to use FlowLayout - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=DFQzFJqOSbAendofvid [starttext] This is a Video Tutorial explains Simple explanation of FlowLayout in java.
[endtext]

84 - Java Programming Tutorial - How to Draw Graphics - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=2l5-5PMUc5Yendofvid [starttext] This is a Video Tutorial explains How to draw basic rectangles ont he screen using java.

[endtext]

85 - Java Programming Tutorial - How to use JColorChooser - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=052U-bWEXrkendofvid [starttext] This is a Video Tutorial explains 85 - Java Programming Tutorial - How to use JColorChooser - [ JAVA Video Tutorial ]

[endtext]

86 - Java Programming Tutorial - How to draw more stuff using java - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=OWOeE90ET6wendofvid [starttext] This is a Video Tutorial explains 86 - Java Programming Tutorial - How to draw more stuff using java - [ JAVA Video Tutorial ]

[endtext]

87 - Java Programming Tutorial - Series Finale - [ JAVA Video Tutorial ]

http://www.youtube.com/watch?v=38UOAo1c_QAendofvid [starttext] This is a Video Tutorial explains 87 - Java Programming Tutorial - Series Finale - JAVA Video Tutorial
[endtext]

Part 1 - Web application with Java Server Faces ,JPA and Top Link - Video Tutorial

http://www.youtube.com/watch?v=RK39z--Si-gendofvid [starttext] This is a Video Tutorial explains
[endtext]

Part 3 - Web application with Java Server Faces ,JPA and Top Link - Video Tutorial

http://www.youtube.com/watch?v=UfCBqxiCsqkendofvid [starttext] This is a Video Tutorial explains Web application with Java Server Faces + JPA Top Link Parte 3
[endtext]

Part 2 - Web application with Java Server Faces ,JPA and Top Link - Video Tutorial

http://www.youtube.com/watch?v=qB6yvcz2Cmgendofvid [starttext] This is a Video Tutorial explains Part 2 - Web application with Java Server Faces ,JPA and Top Link - Video Tutorial
[endtext]

How to use The JSF commandButton Element - JSF Video Tutorial

http://www.youtube.com/watch?v=fcibYwuP9akendofvid [starttext] This is a Video Tutorial explains how to create a button using JSF. The code sample as well as many other samples, video clips and exercises can be found at www.abelski.com.

[endtext]

How to create links in JSF - JSF Video Tutorial

http://www.youtube.com/watch?v=5OkrqQToYK8endofvid [starttext] This is a Video Tutorial explains how to create links in JSF. This video clip shows how we can use the commandLink and the outputLink JSF tags.

[endtext]

simple JSF Facelet code sample - JSF Video Tutorial

http://www.youtube.com/watch?v=NBU3EfPYaW0endofvid [starttext] This is a Video Tutorial explains a simple JSF Facelet code sample that you can find within the JavaServer Faces course at www.abelski.com, where you can also download the code itself.

[endtext]

How to create JSF form and use JavaScript to interact with its controls - JSF Video Tutorial

http://www.youtube.com/watch?v=GKc9BVa1M14endofvid [starttext] This is a Video Tutorial explains how we can create a form and use JavaScript to interact with its controls.

[endtext]

Automatic file backup

I'm inspired by a real world need I have to create utility in Liberty BASIC which will do the following:

1) Periodically examine a list of files in a folder to see if they have changed
2) Make a new folder with a unique name somewhere else to contain the updated files
3) Copy the changed files to the new folder

We can keep a list of paths and files in a file, create a simple gui for maintaining this list and starting and stopping the timer, and for displaying a log of activity.

In our next installment we will write the GUI code.

Projects

I've decided to start some small projects which show how to do various things in Liberty BASIC. This will be a good way to demonstrate how easy programming in BASIC can be, and it will help people to learn specific programming techniques.

A generic sort program with 'functors' and 'templates'

Picked up this question from here and made a program out of it. It may be a good idea to quickly brush functors and templates if required.

The program sorts the input Vector provided regardless of the type.




//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace
std;

class
Int
{

public
:
Int() {x_ = 0;}
Int(const int &x) {x_ = x;}
int
getID (void) {return x_;}
int
x_;
};


class
Str
{

public
:
Str() {x_ = "";}
Str(const string &x) {x_ = x;}
string getID (void) {return x_;}
string x_;
};


template
<typename Object> class Comparator {
public
:
bool
operator()(const Object &o1, const Object &o2) const
{

return
(const_cast<Object&>(o1).getID() < const_cast<Object&>(o2).getID());
}


bool
operator()(const Object *o1, const Object *o2) const {
return
(o1->getID() < o2->getID());
}
};


template
<typename VecObject> void Display(VecObject v)
{

VecObject::iterator it;
for
(it = v.begin(); it != v.end(); ++it)
{

cout<<it->getID()<<", ";
}

cout<<endl;
}


int
main()
{

vector<Int> objects1;
objects1.push_back(Int(3));
objects1.push_back(Int());
objects1.push_back(Int(77));

//print the output
cout<<"objects1 before sort = ";
Display(objects1);
std::sort(objects1.begin(), objects1.end(), Comparator<Int> ());
cout<<"objects1 after sort = ";
Display(objects1);

std::vector<Str> objects2;
objects2.push_back(Str("Hello Hello"));
objects2.push_back(Str("apple?"));
objects2.push_back(Str());
objects2.push_back(Str("1 Jump"));

//print the output
cout<<"objects2 before sort = ";
Display(objects2);
std::sort(objects2.begin(), objects2.end(), Comparator<Str> ());
cout<<"objects2 after sort = ";
Display(objects2);

return
0;
}




The output is as follows:

(1 of 5) - JSP + Servlets + EJB - Java EE 6 and GlassFish 3 with NetBeans 6.9

http://www.youtube.com/watch?v=pwBNmAhtqk8endofvid [starttext] This multi-part screencast series shows how NetBeans 6.9 provides comprehensive tooling for Java EE 6 & GlassFish 3. The different parts show:

1. A simple Java EE 6 application (JSP, Servlets, EJB)
2. Reading database table using Java Persistence API 2
3. Using Facelets with Java Server Faces 2
4. Contexts & Dependency Injection with JSF 2
5. RESTful Web services using JAX-RS

This is part 1
[endtext]

(2 of 5) - Java Persistence API 2 - Java EE 6 and GlassFish 3 application with NetBeans 6.9

http://www.youtube.com/watch?v=_D_vphsAM-Yendofvid [starttext] This multi-part screencast series shows how NetBeans 6.9 provides comprehensive tooling for Java EE 6 & GlassFish 3. The different parts show:

1. A simple Java EE 6 application (JSP, Servlets, EJB)
2. Reading database table using Java Persistence API 2
3. Using Facelets with Java Server Faces 2
4. Contexts & Dependency Injection with JSF 2
5. RESTful Web services using JAX-RS

This is part #2.
[endtext]

(3 of 5) - Facelets and JSF 2 - Java EE 6 and GlassFish application 3 with NetBeans 6.9

http://www.youtube.com/watch?v=-Q25P-oSUJ8endofvid [starttext] This is a Video Tutorial explains This multi-part screencast series shows how NetBeans 6.9 provides comprehensive tooling for Java EE 6 & GlassFish 3. The different parts show:

1. A simple Java EE 6 application (JSP, Servlets, EJB)
2. Reading database table using Java Persistence API 2
3. Using Facelets with Java Server Faces 2
4. Contexts & Dependency Injection with JSF 2
5. RESTful Web services using JAX-RS

This is part #3.
[endtext]

(4 of 5) - CDI with JSF 2 - Java EE 6 and GlassFish 3 application with NetBeans 6.9

http://www.youtube.com/watch?v=D1fyKOTO5rwendofvid [starttext] This is a Video Tutorial explains This multi-part screencast series shows how NetBeans 6.9 provides comprehensive tooling for Java EE 6 & GlassFish 3. The different parts show:

1. A simple Java EE 6 application (JSP, Servlets, EJB)
2. Reading database table using Java Persistence API 2
3. Using Facelets with Java Server Faces 2
4. Contexts & Dependency Injection with JSF 2
5. RESTful Web services using JAX-RS

This is part #4.
[endtext]

(5 of 5) - RESTful Web services using JAX-RS - Java EE 6 and GlassFish 3 application with NetBeans 6.9

http://www.youtube.com/watch?v=qf2Jxwpbsuoendofvid [starttext] This is a Video Tutorial explains Java EE 6 and GlassFish 3 application with NetBeans 6.9 (5 of 5) - RESTful Web services using JAX-RS

This multi-part screencast series shows how NetBeans 6.9 provides comprehensive tooling for Java EE 6 & GlassFish 3. The different parts show:

1. A simple Java EE 6 application (JSP, Servlets, EJB)
2. Reading database table using Java Persistence API 2
3. Using Facelets with Java Server Faces 2
4. Contexts & Dependency Injection with JSF 2
5. RESTful Web services using JAX-RS

This is part #5.
[endtext]

How to Create a Java Server Faces (JSF) Development Environment w Apache Tomcat + Suns JDK

http://www.youtube.com/watch?v=KmvRUnNRytoendofvid [starttext] This is a Video Tutorial explains This is part one of a three part Java Server Faces CBT Tutorial that demonstrates how to configure your Windows XP environment in order to do some JSF development.

The idea is that first you need to install the JDK, configure the JAVA_HOME environment variable, and then install the Tomcat Servlet & JSP engine. With the JAVA_HOME set, and the bin directory of the Tomcat6 server located, it's just a matter of running the startup.bat file and your tomcat server can be found at http://localhost:8080

After installing and configuration Tomcat, further tutorials demonstrate how to obtain the JSF JAR files from the mojarra project (jsf-api.jar & jsf-api.jar). We even recommend finding the jstl.jar and standard.jar files from the examples in the Tomcat installation.

Subsequent tutorials demonstrate how to create a simple J2EE/JEE5 war file with the appropriate war file structure, how to create a web.xml deployment descriptor, a faces-config.xml file, and finall, how to jar the whole darn thing up and deploy it to the Servlet Engine.

This tutorial uses Apache Tomcat, but the instructions will work with any J2EE/JEE5 compliant application server, including WebSphere, WebLogic, Tomcat, Oracle, etc.
[endtext]

How to Create a Simple Java Server Faces (JSF) Application WAR File for J2EE/JEE5 Deployment

http://www.youtube.com/watch?v=fGNAseUrr-gendofvid [starttext] This is a Video Tutorial explains How to Create a Simple Java Server Faces (JSF) Application WAR File for J2EE/JEE5 Deployment
Part II of a three part tutorial, this tutorial demonstrates how to put together a basic JSF war file for deployment to a Tomcat 6 server, although the simple WAR file can be deployed to any Servlet Engine, be it WebSphere, WebLogic, Glassfish, Oracle, etc.

This tutorial demonstrates how to create a proper war structure, do a basic web.xml deployment descriptor configuration for the FacesServlet that implements the FrontController Design Pattern, and it shows a simple faces-config.xml file.

A HelloWorld Java Server Page (JSP), helloworld.jsp, is created that is then invoked through the JSF framework on the Tomcat6 server to ensure the JSF1.2 environment is configured properly.

[endtext]

JSF 2.0 Standard Custom Tags: JavaServer Faces 2.0 Video Tutorial

http://www.youtube.com/watch?v=7wvXw75vvxMendofvid [starttext] This is a Video Tutorial explains This tutorial simply picks up from the previous lesson which built a simple JSF application and subsequently deployed that application to Tomcat 7. Here we explore three of the four custom tag libraries that are part of the standard JavaServer Faces distribution, namely the HTML, Core and UI tag libraries. We save the composite tag library for a future tutorial.

This tutorial doesn't get too crazy, as it really is just designed to help you ensure that everything is working properly, and that indeed you can use the various JSF custom tags on your xhtml pages. I will say that the discussion of the ui:debug tag is pretty kewl, especially if you are a JSF 1.2 developer who doesn't have any familiarity with the new JSF 2.0 custom tag library additions

[endtext]

How to make SSL in Tomcat - Detailed Step by step to make the SSL in tomcat - Video Tutorial

http://www.youtube.com/watch?v=Y7u4RAhuQV0endofvid [starttext] This is a Video Tutorial explains Detailed Step - by - step to make the SSL in tomcat

[endtext]

How to configure Tomcat 7 for JSF 2.0 - CDI (Context & Dependency Injection) and JBoss - JSF Video Tutorial

http://www.youtube.com/watch?v=q30ICO30FGsendofvid [starttext] This is a Video Tutorial explains So, how do you use the JSR299 annotations in a JSF 2.0 application that's going to be deployed to Tomcat 7? Well, by default, Tomcat 7 does not support JSR-299, the CDI (Context and Dependency Injection) specification. So, to support JSR-299 in your Tomcat deployed web apps, you need to do a little work. One option is to download the MyFaces CODI implementation. The other is to include the JBoss/SeamFramework's implementation of JSR-299, which is better known as "Weld."

This tutorial shows you how to get the required Weld libraries, configure your web.xml file with the required listener, set up the beans.xml file, and do all of the other stuff that's needed to configure Weld in a JSF application that's going to be deployed to servlet engine like Tomcat.

Oh, and just so you know, you do need the beans.xml file if you're working with Weld, even if there is really no content in the file. If you leave it out, you'll run into a runtime exception.

[endtext]

Part 2 of 2 : Managed Beans and JSF 2.0 Handing User Input with Annotated JavaBeans - JSF Video Tutorial

http://www.youtube.com/watch?v=R_n-RidyRE0endofvid [starttext] This is a Video Tutorial explains You can find the full resolution video at http://jsf.mcnz.com The source code is also there as well.

This is the second part of a two part tutorial that shows you how to create a simple JavaServer Faces 2.0 application that takes input from the user through a JSF form, and then provides a response back to the user based on their input. It's essentially a very basic implementation of the old Rock Paper Scissors application, but it's a great way to start learning JSF.

[endtext]

Part 1 of 2 : Managed Beans and JSF 2.0 Handing User Input with Annotated JavaBeans - JSF Video Tutorial

http://www.youtube.com/watch?v=CIDP6KZ81y8endofvid [starttext] This is a Video Tutorial explains Managed Beans and JSF 2.0: Handing User Input with Annotated JavaBeans (Part I of II)

The full resolution video is at http://jsf.mcnz.com So is the source code.

So, if you got a little tired of managing the old faces-config.xml file in your JavaServer Faces 1.2 applications, you're going to love the introduction of the @ManagedBean and @SessionScoped annotations in JSF 2.0.

This tutorial deals with the job of handling user input. How can we take user input from an HTML form using JSF? This tutorial will show you how, using the good old Rock-Paper-Scissors game as the concept that drives the learning.

This tutorial is just beyond the maximum 15 minute length allowed for a youtube video, so it is broken up into two files. Alternatively, if you would like to view the high resolution video in its entirety, you can head over to the associated website, http://jsf.mcnz.com You'll also find the code there to download as well.

[endtext]

Debugging Mutex and Locks

When there are multiple Mutex's in the program, it may be required to find if a particular thread is locked far longer than necessary. This can cause problems and the output may not be what is expected.

To get round this, I took an old example from here and modified it to help me print some debugging info.

I modified the printSomething() in Singleton.h to add a sleep as follows:



  void printSomething(char *name, int count)
{

Lock guard(mutex_);
Sleep(10);
Lock guard2(mutex_);
std::cout << name << " loop " << count << std::endl;
}




and I modified the Mutex.h as follows:



//Example from http://www.relisoft.com/Win32/active.html
#if !defined _MUTEX_H_
#define _MUTEX_H_

class
Mutex
{

friend class
Lock;
public
:
Mutex () { InitializeCriticalSection (& _critSection); }
~
Mutex () { DeleteCriticalSection (& _critSection); }
private
:
void
Acquire ()
{

DWORD start = GetTickCount();
EnterCriticalSection (& _critSection);
DWORD elapsed = GetTickCount() - start;
if
(elapsed > 15)
{

//Debugging Info
std::cout<<"Debugging Info: Waited at mutex for "<<elapsed<<std::endl;
}
}

void
Release ()
{

LeaveCriticalSection (& _critSection);
}


CRITICAL_SECTION _critSection;
};


#endif



The output is as follows:
The small problem with the above approach is that if a Thread is deadlocked, we may not get the debug output as we would have to kill the process.

Red5 Problem - Red5plugin not working - Red5 Video Tutorial

http://www.youtube.com/watch?v=GnGcx0Sw8bEendofvid [starttext] This is a Video Tutorial explains how to fix Red5plugin not working

I cannot get rid of the Server Runtimes and they are mounting up.

I cannot get rid of the Runtime Configurations and they are mounting up.

I can only get 2 Applications to work using the Red5plugin...all applications after that do not work. I can get the server app to work but not the client app...the message box says Unsucessful Connection.
[endtext]

Red5 Problems - Red5 Questions - Red5 Video Tutorial

http://www.youtube.com/watch?v=TR8Wxv3UF78endofvid [starttext] This is a Video Tutorial explains


How do I delete/edit a target runtime?
How do I delete/edit runtime configurations?
When do I use the Red5 service I installed, and when do I use the Red5 distribution I built (they can't be running at the same time...I can only use one at a time).

UPDATE: I think I may know the answer to this.

You use the installed Red5 service in the following scenerios:
When you deploy it to a server
When you run an application that is not built with the Red5plugin

You use the Red5 distribution in the following scenerios:
When you run a Red5plugin application (you run it, and you must stop the installed service)
The distribution is used to build red5 projects (with or without plugin). But you can still use the installed service to run it...you need not run it using the distribution.
I installed ANT, but never used it. Should I uninstall it?

UPDATE: I think it is used when I created a non-plugin Red5 Application. It may also be used when I create a Red5plugin application, but I'm not totally sure. I think I'll leave it installed.
[endtext]

How to Install Red5 0.9 on Windows - Red5 Video Tutorial

http://www.youtube.com/watch?v=nQq3hknC2Nsendofvid [starttext]
This is a Video Tutorial explains How to How to Install Red5 0.9 on Windows
[endtext]

Video Tutorial Red5 - Install JDK/JRE on Windows (for Red5)

http://www.youtube.com/watch?v=7XvwxRVxgHsendofvid [starttext] This is a Video Tutorial explains
1. Go to http://java.sun.com/, mouse over Downloads in the top menu bar, and choose Java SE. Click on Download JDK button. Then select your platform (select 32-bit version for windows even if you have 64-bit), check the checkbox to accept the terms and click the Download button. Then click on the jdk-6u18-windows-i586.exe link to download it. Click Save button.

NOTE: The latest version right now is JDK 6 Update 18, and the filename is jdk-6u18-windows-i586.exe.

IMPORTANT: Even if you have a 64-bit computer, you should download the 32-bit version of the JDK. Eclipse seems to want the 32-bit version.

I tried installing the 64-bit version and I got this error when I start Eclipse:
A Java Runtime (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse.
No Java Virtual Machine was found.
2. Double click on the jdk-6u18-windows-i586.exe file on your computer to install the JDK. First it will install the JDK then it will install the JRE. It will ask you where on your computer to install each of them. You can just leave the default, which is C:\Program Files (x86)\Java\jdk1.6.0_18 and the JRE in C:\Program Files (x86)\Java\jre6.

NOTE: Usually, I like to keep 32-bit software in C:\Program Files and 64-bit software in C:\Program Files (x86). But for some reason, Sun has decided to install java by default to opposite folders...32-bit version in C:\Program Files (x86) and 64-bit version in C:\Program Files. I tried flipping them around and I got errors during installation...so I just ended up leaving the defaults.
3. And now the JDK/JRE are installed. Go to C:\Program Files (x86)\Java (or wherever you installed it) and you will see two folders: jdk1.6.0_18 and jre6.

[endtext]

Red5 Video Tutorial - Install Eclipse on Windows (for Red5)

http://www.youtube.com/watch?v=FZXUgXtjlEEendofvid [starttext] This is a Video Tutorial explains how to Install Eclipse on Windows (for Red5)

Go to http://www.eclipse.org/downloads/, then click on the link that says Eclipse IDE for Java EE Developers (189 MB), then download it and save it to your hard drive. The file is named eclipse-jee-galileo-SR1-win32.zip.

Extract eclipse-jee-galileo-SR1-win32.zip anywhere on your computer. I have extracted it to C:\Program Files (it will make a new directory called eclipse, so it will end up being located in C:\Program Files\eclipse.

NOTE: Eclipse does not need to be installed, all you have to do is extract it. You can create a desktop shortcut to the eclipse.exe file to make it easier to access later.

TO RUN ECLIPSE: double click on eclipse.exe, then click the Run button. Then browse to a folder where you want to store your eclipse projects (otherwise known as your workspace). I have used C:\Documents and Settings\Administrator\My Documents\Eclipse. Then click the OK button and eclipse will start up.
[endtext]

How to Install Ant on Windows (for Red5) - Red5 Video Tutorial

http://www.youtube.com/watch?v=9nXBzFtbCbcendofvid [starttext] This is a Video Tutorial explains How to Install Ant on Windows (for Red5)
[endtext]

How to Set environment variables for Red5 - Red5 Video Tutorial

http://www.youtube.com/watch?v=b_y5tCxBrIQendofvid [starttext] This is a Video Tutorial explains How to Set environment variables for Red5

Open your Control Panel, then double click on System, then click on the Advanced tab, then click on Environment Variables button.

ADD ANT TO PATH: Find Path variable in your list of System Variables, click on it, then click on Edit button. Now add the path to the bin directory of your Ant installation (C:\Program Files\ANT\bin) to the end of your path. Make sure to separate it from the list of paths with a semicolon (each path in the list is separated by a semicolon). Be sure to not replace what is there, just add to the end. Now click OK button.

ADD JDK TO YOUR PATH: Find Path variable in your list of System Variables, click on it, then click on Edit button. Now add the path to the bin directory of your JDK installation (C:\Program Files (x86)\Java\jdk1.6.0_18\bin) to the end of your path. Make sure to separate it from the list of paths with a semicolon (each path in the list is separated by a semicolon). Be sure to not replace what is there, just add to the end. Now click OK button.

NOTE: When you add JDK to your path, instead of adding it as C:\Program Files (x86)\Java\jdk1.6.0_18\bin, you could have added it as %JAVA_HOME%\bin. %JAVA_HOME%\bin would reference the JAVA_HOME variable we define below and would resolve to C:\Program Files (x86)\Java\jdk1.6.0_18

ADD JAVA_HOME VARIABLE: Click on New button to add a new system variable. For the name, type in "JAVA_HOME". For the value, put the path to your jdk installation, C:\Program Files (x86)\Java\jdk1.6.0_18. Then click the OK button.

ADD JAVA_VERSION VARIABLE: Click on New button to add a new system variable. For the name, type in "JAVA_VERSION". For the value, put 1.6 (the version of the jdk you installed). Then click the OK button.

TEST IT: If you have a command prompt open, then close it and open a new one (the old one won't recognize the changes to environment variables). In the new command prompt, type in "ant", and it should say "build.xml does not exist" (we'll fix that later). Now type in "set JAVA_HOME", and it should display the path you entered for JAVA_HOME. Now type in "set JAVA_VERSION" and it should display 1.6.

NOTE: If you had eclipse open, while you made changes to your environment variables, then you should close it and open it again. Otherwise, it will not recognize the changes you made to your environment variables.
[endtext]

How to Install Subversion (TortoiseSVN) on Windows (for Red5) - Red5 Video Tutorial

http://www.youtube.com/watch?v=pG9aR5I6RT0endofvid [starttext] This is a Video Tutorial explains How to Install Subversion (TortoiseSVN) on Windows (for Red5)

Go to http://tortoisesvn.net/downloads, scroll down to where it says Download Application then choose your version, 32 bit or 64 bit, and click on the msi file (I chose the 64bit version and that is called TortoiseSVN-1.6.7.18415-x64-svn-1.6.9.msi). Then click on direct link and press Save button to save it to your hard drive.

NOTE: TortoiseSVN is one of many SVN products out there. Someone recommended it to me and told me that it works very well on Windows. There are other SVN products located at http://subversion.tigris.org/ and http://subversion.apache.org/. I really like TortoiseSVN because it is easy to use, and I don't have to use the command prompt to use it.

Double click on the TortoiseSVN-1.6.7.18415-x64-svn-1.6.9.msi file on your computer to install Tortoise SVN. By default it will be installed to C:\Program Files\TortoiseSVN. Then restart your computer for the changes to take effect.
[endtext]

How to check out Red5 source with Subversion (TortoiseSVN) - Red5 Video Tutorial

http://www.youtube.com/watch?v=3hfWgTN_qnkendofvid [starttext] This is a Video Tutorial explains how to Check out Red5 source with Subversion (TortoiseSVN)

[endtext]

How to Install Ivyde on Windows (for Red5) - Red5 Video Tutorial

http://www.youtube.com/watch?v=5iTmwIqlhsQendofvid [starttext] This is a Video Tutorial explains How to Install Ivyde on Windows (for Red5)
[endtext]

How to Install Subclipse on Windows (for Red5) - Red5 Video Tutorial

http://www.youtube.com/watch?v=Q9ZlXegZDLkendofvid [starttext] This is a Video Tutorial explains How to Install Subclipse on Windows (for Red5)


Go to http://subclipse.tigris.org/, then click on Download and Install tab, then under where it says Current Release, find the latest release and copy the Eclipse update site URL.

Eclipse update site URL: http://subclipse.tigris.org/update_1.6.x

Open eclipse, click on Help in the top menubar, then click on Install New Software, then click the Add button. Then for name, type in Subclipse and for location, copy it from the Subclipse site (in step 1).

(In eclipse: in the name field, use Subclipse and in the location field, use http://subclipse.tigris.org/update_1.6.x.) Then click OK.

There will be a list of items with checkboxes....check all boxes in the list. They should say:

Core SVNKit Library
Optional JNA Library
Subclipse

Expand each of the above items and make sure all checkboxes under them are checked. Then click Next », then click Next » again, then check the box to accept the terms, the click Finish, and wait while it downloads Subclipse.

If you get a warning message like the one below, then just click OK:

Warning: You are installing software that contains unsigned content. The
authenticity or validity of this software cannot be established. Do you want to
continue with the installation?

Then click Yes to restart eclipse.
[endtext]

How to Build Red5 Distribution - Red5 Video Tutorial

http://www.youtube.com/watch?v=6_ddwvivzhoendofvid [starttext] This is a Video Tutorial explains How to Build Red5 Distribution - Red5 Video Tutorial
[endtext]

How to Install Red5plugin on Windows - Red5 Video Tutorial

http://www.youtube.com/watch?v=ua_CVxZnBxgendofvid [starttext] This is a Video Tutorial Shows you how to install the Red5plugin on Windows.

But first you must install the following 3 programs:

Ivyde:
http://j2ee-tutorials-videos.blogspot.com/2011/02/how-to-install-ivyde-on-windows-for.html

Subclipse:
http://j2ee-tutorials-videos.blogspot.com/2011/02/how-to-install-subclipse-on-windows-for.html

FlashBuilder:
http://j2ee-tutorials-videos.blogspot.com/2011/02/how-to-install-flashbuilder-for-red5.html

The links above will show you how to install each of the 3 programs.
[endtext]

How to Install Flashbuilder (for Red5) - Red5 Video Tutorial

http://www.youtube.com/watch?v=PMWGep79S2Qendofvid [starttext] This is a Video Tutorial explains How to Install Flashbuilder (for Red5)
[endtext]

How to Run Red5 Distribution - Red5 Video Tutorial

http://www.youtube.com/watch?v=bplO44DQmvAendofvid [starttext] This is a Video Tutorial explains How to Run Red5 Distribution - Red5 Video Tutorial


[endtext]

red5-shutdown.bat and red5-debug.bat - Red5 Video Tutorial

http://www.youtube.com/watch?v=E7MePjxxc8cendofvid [starttext] This is a Video Tutorial explains red5-shutdown.bat and red5-debug.bat

Go to your red5_server eclipse project dist directory (C:\Documents and Settings\Administrator\My Documents\Eclipse\red5_server\dist), and open the red5-shutdown.bat file in notepad. Find the line that says:

%RED5_HOME%\red5.bat
and put quotes around it so that it now reads:
"%RED5_HOME%\red5.bat"

Now open the red5-debug.bat file in notepad. Find the line that says:

%RED5_HOME%\red5.bat
and put quotes around it so that it now reads:
"%RED5_HOME%\red5.bat"

TEST IT: double click on red5-debug.bat to start red5 service. Then double click on red5-shutdown.bat to stop it.
[endtext]

How to Build Multiple Red5 Distributions - Red5 Video Tutorial

http://www.youtube.com/watch?v=wklnf1l7DyIendofvid [starttext] This is a Video Tutorial explains how to Build Multiple Red5 Distributions

Open eclipse, and open your red5_server project (that we build in a previous video), delete the dist folder (we will be recreating this folder in a minute and putting multiple distributions, each in their own folder, into this folder). Right click on the project, and click on Refresh.
Click on the Run Last Tool icon in the top nav of eclipse, then click on External Tools Configuration, and where it says Arguments, type in: -Ddist.dir=dist/r1 (where r1 stands for revision

1...you can name each revision r1, r2, r3, etc.), then click the Apply button, then click the Run button...and it will compile and it should say BUILD SUCCESSFUL. Now right click on your project and click on Refresh and you'll see the new r1 directory in your dist directory.

TO MAKE A SECOND DISTRIBUTION: Click on the the Run Last Tool icon in the top nav again, then click on External Tools Configuration, and where it says Arguments, type in: -Ddist.dir=dist/r2 (change the 1 to a 2), then click the Apply button, then click the Run button...and it will compile and it should say BUILD SUCCESSFUL. Now right click on your project and click on Refresh and you'll see the new r2 directory in your dist directory.

NOTE: The reason to create multiple Red5 distributions, is so that we can keep getting the latest Red5 source, without having to go back and update all our old projects.... so we can have different projects using different build distributions of Red5.

[endtext]

How to Run Red5 Distribution in Eclipse - Red5 Video Tutorial

http://www.youtube.com/watch?v=01Q-e9KyOmYendofvid [starttext] This is a Video Tutorial explains How to Run Red5 Distribution in Eclipse

In this video we will run the r1 distribution we created in the last video inside eclipse. In order to run the red5 distribution, we need to create a runtime configuration.

Open eclipse and open the red5_server project, click on the Run arrow icon, click on Run Configurations, Right click on Java Application in the left sidebar, and click on New.
For the Project:, type in red5_server (that is the project that has our red5_distribution).

For Main Class, click on the Search button, type in bootstrap, then click on the item in the list that says Bootstrap - ord.red5.server, then click OK.

Then give the distribution a name in the Name: box, type in Distribution r1 (that way we will know that this Runtime Configuration is for the r1 distribution).

Now click on the Arguments tab, then click on the Other radio button, then click on the Workspace button, then expand the red5_server project, then expand the dist folder, and then click on r1 folder. Then click OK button.

Then click on the classpath tab, then click on red5_server and click on Remove button. Then click on User Entries and click on Add JARS button. Expand the red5_server project, and expand the dist folder, then expand r1 folder, then click on boot.jar. Then click on OK button. Then click on the Apply button. Then click on the Run button. And it will compile, and then it will say "Installer Service Created".

To stop Red5, click on the Red stop button.

[endtext]

How to Debug Red5 source Code - Red5 Video Tutorial

http://www.youtube.com/watch?v=EthwDjf3W9Mendofvid [starttext] This is a Video Tutorial explains How to Debug Red5 source Code

First create a debug configuration in eclipse. Click on the Debug icon in the top nav, then click on Debug Configurations, then click on the Source tab, then click on the Add button, then click on Java Project and click OK, then check the checkbox next to red5_server project, then click OK button. Then click Apply button, then click Debug button, and wait for it to compile. When it is done compiling, it should say: INSTALLER SERVICE CREATED

Press the red stop button, to stop it.

TO SET BREAKPOINT: type ctrl+shif+r, type in bootstrap, and select Bootstrap.java in the list, and click Open button, and it will open Bootstrap.java. Bootstrap.java has the main function which gets called when Red5 first starts. Set a breakpoint on the line that reads: public static void main(String args) To set the breakpoint double click on the left edge of the file on that line.

TO TURN ON LINE NUMBERING: click on Window in the top nav, then click on Preferences, then expand General, then expand Editors, then click on Text Editors, then check the box that says Show line numbers, and then click OK button. And now the line numbers will appear on the left of each line (making it easier to keep track of breakpoints).

TO DEBUG: Click on the Debug icon in the top nav again, then click on Distribution r1, a message will popup asking if we want to open the debug perspective...click the Yes button. And now it will go to our first breakpoint.

Use f5 to step into.
Use f6 to step over.

TO STOP DEBUGGING: click on Run in the top nav, then click on Terminate.

TO RESET THE LAYOUT: click on Window in the top nav, then click on Open Perspective, then click on Java EE.

[endtext]

How to Create Red5 Application (without Red5plugin) - Red5 Video Tutorial

http://www.youtube.com/watch?v=szgG9sFD7IQendofvid [starttext]

Go to http://code.google.com/p/red5/, scroll down to where it says Red5 0.9.0 Final, and click on the ZIP link, and save the file, red5-0.9.0.zip to your hard drive.
Scroll back up on the google site and click on Updates in the top nav, then click on r4037 (or whatever the latest is), click on /java/server/trunk/project.zip link, then right click on View Raw File, choose Save Target As, and save project.zip to your hard drive (to the same place where you saved the red5-0.9.0.zip.)
Scroll back up on the google site and click on trunk in the top nav, click on util.xml at the bottom of the list, right click on View Raw File, choose Save Target As, and save util.xml to your hard drive (to the same place where you saved the other 2 zips)
Now that all 3 files are saved to the same location, extract the red5-0.9.0.zip file (extract it to the same location as the zips). Extracting red5-0.9.0.zip will put a new lib folder there, and we will save something there in the next step.
Click on the Source tab on the Google site, and copy the URL from this line and paste in in your browser:
svn checkout http://red5.googlecode.com/svn/java/server/trunk/ red5-read-only
then click on the lib link, then right click on ivy-2.1.0.jar link and select Save Target As and save it to your hard drive. Save it to the lib folder that was created when you extracted red5-0.9.0.zip.
Open the build.properties file in Wordpad. (will be in the root of the folder where you extracted red5-0.9.0.zip). Find the ivy.version and make sure it is the same one you downloaded. (it should say ivy.version=ivy-2.1.0 if you downloaded ivy-2.1.0.jar).
Open a command prompt, and go to the directory where you downloaded the files and extracted red5-0.9.0.zip.
This is what I typed in the command prompt to change directories:
D:
cd D:\Red5\red5_project_maker

Now type in:
ant -f util.xml project

and now it will ask 3 questions about my project, so that it can create it for me:
[input] Please enter your projects name (ie. mycoolred5app):
testapp
[input] Please enter your workspace path (ie. c:\\eclipse\\workspace): [c:/eclipse/workspace]
C:\Documents and Settings\Administrator\My Documents\Eclipse
[input] Please enter your package namespace (ie. org.red5): [org.red5.app]:
com.testapp


Now it should say BUILD SUCCESSFUL, which means it has created the project for me.
If you go to your Eclipse workspace folder, you will see it has created a new testapp folder with the application in it.
IMPORT THE PROJECT TO ECLIPSE: Right click on the Project Explorer, choose Import, click on Import again, then select Existing Projects into Workspace under General, click Next > button. Then where it says Select root directory, give it the location of your testapp directory: C:\Documents and Settings\Administrator\My Documents\Eclipse\testapp, click on the Refresh button, then check the box that says Add project to working sets, then select All in the Working sets dropdown. Then click on Finish and it will import the application.
Right click on the testapp application, select Properties, click on Java Build Path in the left sidebar, then click on Projects tab, and you should see red5_server in the list that says Required projects on the build path. That is the project where we built the red5 distribution. Then click on OK button.
CREATE A SECOND APPLICATION: open the command prompt again. Again type in:
ant -f util.xml project

and again it will ask 3 questions:
[input] Please enter your projects name (ie. mycoolred5app):
testapp2
[input] Please enter your workspace path (ie. c:\\eclipse\\workspcae): [c:/eclipse/workspace]
C:\Documents and Settings\Administrator\My Documents\Eclipse
[input] Please enter your package namespace (ie. org.red5): [org.red5.app]:
com.testapp2


Now it should say BUILD SUCCESSFUL, which means it has created the project for me.
If you go to your Eclipse workspace folder, you will see it has created a new testapp2 folder with the application in it.
IMPORT THE SECOND PROJECT TO ECLIPSE: Right click on the Project Explorer, choose Import, click on Import again, then select Existing Projects into Workspace under General, click Next > button. Then where it says Select root directory, give it the location of your testapp2 directory: C:\Documents and Settings\Administrator\My Documents\Eclipse\testapp2, click on the Refresh button, then check the box that says Add project to working sets, then select All in the Working sets dropdown. Then click on Finish and it will import the application.
Right click on the testapp2 application, select Properties, click on Java Build Path in the left sidebar, then click on Projects tab, and you should see red5_server in the list that says Required projects on the build path. That is the project where we built the red5 distribution. Then click on OK button.

Source: http://www.red5guide.com/create_red5_application_without_plugin.html
[endtext]

How to Add Code to your Red5 Application - Red5 Video Tutorial

http://www.youtube.com/watch?v=WfC3qws9sMEendofvid [starttext] This is a Video Tutorial explains CREATE NEW CLASS THAT EXTENDS APPLICATIONADAPTER: Open eclipse, right click on your red5 project, (testapp for example), and select New, then select Class. In the Package field, type in a package name (com.testapp for example...its probably best to use the same one you typed into the command prompt when creating the project). In the Name field, type in the name for your class, the convention is to name it Application.java (the class that extends ApplicationAdapter is usually called Application.java). Then for the Superclass field, click on the Browse.. button next to it, then type in org.red5.server.adapter., and you can choose between ApplicationAdapter or MultithreadedApplicationAdapter. Most of the time, you'll want to choose MultithreadedApplicationAdapter, so that your application can accept multiple connections at the same time. So click on MultithreadedApplicationAdapter and click on OK button, then click Finish button.
And now it has created a new class called Application which extends MultithreadedApplicationAdapter in the com.testapp package. (notice if you expand Java Resources: src folder in the project explorer, and then expand com.testapp package, you will see the Application.java class) You can override any of the functions in MultithreadedApplicationAdapter, but you don't have to. Any function you put inside this Application class, will be accessible to your client app. So if you put an "add" function like below:
public int add(int a, int b)
{
return a+b;
}
Then you can call it from your client app, with code like this:
nc.call("add", responseHandler, 2, 3);
Expand the www folder in your project, then expand the WEB-INF folder, and open red5-web.xml, find the web.handler bean, and make sure that the class= is set to the right path of your class that extends ApplicationAdapter.
For example, if your class that extends ApplicationAdapter is called Application and it is in the com.testapp directory, then the web.handler bean's class should be set to com.testapp.Application. Like so:

If you open red5-web.properties inside www/WEB-INF, you will see the contextPath is equal to testapp (by convention it will be the same as the project name). This is the name used by the client app to connect in the rtmp path (for example rtmp://localhost/testapp).

NOTE: if you open web.xml and logback-testapp.xml, you will also see testapp within them... all these things need to match so it's best to leave it alone.

TIP: if you open the xml files, and they are in Design mode, click on the Source tab at the bottom of the file and it will be easier to modify and work with.
[endtext]

How to Deploy Red5 Application on Eclipse - Red5 Video Tutorial

http://www.youtube.com/watch?v=xHxAFfRRODUendofvid [starttext] This is a Video Tutorial explains
MAKE A WAR FILE: open a command prompt, and go to the directory where the application to deploy is located, like this:
cd C:\Documents and Settings\Administrator\My Documents\Eclipse\testapp

Now type in: ant -p
(this will list all the targets in the ant build file for this project)

Now type in:
ant

It should say BUILD SUCCESSFUL. This means you have built the war file.
A new dist directory will have been created inside your project directory. Go to the dist directory of your project, for example: cd C:\Documents and Settings\Administrator\My Documents\Eclipse\testapp\dist and you will see the war file there called testapp.war. Copy that war file and paste it into the webapps directory where you installed Red5. For example: C:\Program Files\Red5\webapps. Within 10 minutes, this war file will be turned into a directory called testapp and the project will be located there. (Red5 service has a WarDeployerService that runs every 10 minutes) But first you need to restart red5 (next step).

RESTART RED5: Open Control Panel, click on Administrative Tools, click on Services, find the Red5 service, right click on it and choose Stop, then right click on it again and choose Start
CONFIGURE WARDEPLOYERSERVICE INTERVAL: If you don't want to wait 10 minutes for the war file to deploy itself, you can change that 10 minute value. Go to the conf directory where you installed Red5, for example: C:\Program Files\Red5\conf, open the red5-common.xml file in notepad, find the WarDeployerService bean and change the checkInterval value. By default it is 600,000 miliseconds (or 10 minutes).





(On your local computer you may want to make it smaller so you don't have to wait 10 minutes, but on your server, you may want to leave it 10 minutes, because you won't deploy it as often, and it may take up extra resources to set it lower.)
TO MAKE CHANGES TO YOUR PROJECT AFTER LAUNCH: delete the war file and delete the new directory it creates. Copy the new war file into the webapps directory. Stop and start Red5, then wait 10 minutes for the WarDeployerService to deploy the war file and create the testapp directory.

[endtext]

Red5 Tutorial - Create Client Application to Access Red5 Server Application

http://www.youtube.com/watch?v=6MLL_krbuqEendofvid [starttext] This is a Video Tutorial explains
Create a new fla file, and with frame 1 selected, open the Actions panel and type in the following code:
import flash.net.NetConnection;
import flash.net.Responder;

var nc:NetConnection = new NetConnection();
nc.connect("rtmp://localhost/testapp");
nc.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

var nr:Responder = new Responder(netResponderHandler);
nc.call("add", nr, 2, 3);

function netConnectionHandler(evt:NetStatusEvent)
{
trace("status: " + evt.info.code);
}

function securityErrorHandler(evt:SecurityErrorEvent):void
{
trace("securityErrorHandler: " + evt);
}

function netResponderHandler(serverResult:Object)
{
trace("The result is " + serverResult);
}
First we import the namespaces flash.net.NetConnection and flash.net.Responder, then we create a new NetConnection object, and then we connect to the server app using the path rtmp://localhost/testapp (where testapp is the name of the contextPath inside red-web.properties of the server app). Then we add an event listener, NET_STATUS, that listens for status information of the connection (like Success, Failure, or InvalidApp. Then we add an event listener SECURITY_ERROR to listen for security errors.

Next we want to call the add() function on the server app, so we use this syntax:

var nr:Responder = new Responder(netResponderHandler);
nc.call("add", nr, 2, 3);

We use nc.call("add", nr, 2, 3) to call the server app function, and we pass it the nr responder object. That object is created and passed an event handler called netResponderHandler() which will recieve the results of the add() function, as it's parameter. If we pass 2 and 3 to the add() function then netResponderHandler() will receive 5 as its serverResult parameter.
RUN THE FLA FILE: Click on Control in the top nav, then click Test Movie, and in the console the output should be:

status: NetConnection.Connect.Success
The result is 5


NOTE: If you get a status of NetConnection.Connect.InvalidApp, then try restarting your computer. That is what I had to do. I also noticed that when I restarted my computer, the testapp.war file had disappeared from my webapps directory where Red5 is installed (which is fine because it is not needed...it is only there to deploy the project...once it is deployed it is not needed anymore.)
[endtext]

Add two unsigned integers without using '+'

I found this very interesting discussion (and the program) to add two numbers without the use of the arithmetic operator '+'. The obvious guess would be to use the Bitwise operators.

The logic behind the addition operation using the bitwise operators is as follows:


integer1 =  3  = 0011b
integer2 = 5 = 0101b

first operation second operation third operation
0011 0011
shift by one
0101 0101

______ ______
XOR 0110 AND 0001 ------> <<1 0010

Again...
first operation second operation third operation
previous XOR 0110 0110 shift by one
previous <<1 0010 0010
______ ______
XOR 0100 AND 0010 ------> <<1 0100

Again...
first operation second operation third operation
previous XOR 0100 0100 shift by one
previous <<1 0100 0100
______ ______
XOR 0000 AND 0100 ------> <<1 1000

Again...
first operation second operation
previous XOR 0000 0000
previous <<1 1000 1000
______ ______
XOR 1000 AND 0000
When AND iguals 0 the result of XOR is iqual to the sum of the two integers

The program is as follows:



//Program to add two numbers by using boolean operators
//Ref: http://www.daniweb.com/forums/thread84950.html
//Program tested on Microsoft Visual Studio 2008 - Zahid Ghadialy
#include<iostream>

using namespace
std;

unsigned long
add(unsigned integer1, unsigned integer2)
{

unsigned long
xor, and, temp;

and
= integer1 & integer2; /* Obtain the carry bits */
xor
= integer1 ^ integer2; /* resulting bits */

while
(and != 0 ) /* stop when carry bits are gone */
{

and
<<= 1; /* shifting the carry bits one space */
temp = xor ^ and; /* hold the new xor result bits*/
and
&= xor; /* clear the previous carry bits and assign the new carry bits */
xor
= temp; /* resulting bits */
}

return
xor; /* final result */
}


int
main()
{

int
num1 = 13, num2 = 27;

cout << num1 << " + " << num2 << " = " <<add(num1, num2) << endl;

return
0;
}



The output is:
13 + 27 = 40

See the original discussion here.

Check out this stream