Find Your Code From Koders Engine:

Sunday, January 30, 2011

How to create an AJAX contact form

This tutorial shows users how to create an AJAX contact form. The form method in this tutorial is set to POST.
 The AJAX Contact Form uses the POST method to transfer the data from the form to the PHP file. From thereon you can store the data in variables using "$_POST". This is also illustrated in the code.

There are two pages that you will need. The first page will show the form to the user when the user first visits the page. We will call this page "Form.php". The other page will process the data from the first page and will return a confirmation message. You can use PHP or any other language to do anything you want. We are going to call the second page "Process.php".

To get started, first create a form: like displayed in figure

There are two <span> sections defined in this page. The first one is highlighted in orange in the above image and the second span is the table that holds the input fields.

The status span will display the status of the form while it is being processed. Once all the information has been processed, the status will read "Ready".

Following is the code for the Form.php file:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AJAX Contact Form NabeelAkhtar.NET</title>
<link rel="stylesheet" type="text/css" href="../../../style.css">
<!------------------------------------------------ AJAX CODE ---------------------------------->
<script type="text/javascript" language="javascript">
var http_request = false;

function show_hint ( p_hint_text, p_span ) {
document.getElementById(p_span).innerHTML = p_hint_text ;
}

function makePOSTRequest(url, parameters, SpanName) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById(SpanName).innerHTML = result;
document.getElementById('status').innerHTML = 'Ready';
} else {
alert('There was a problem with the request.');
}
}
};
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}

function Contact(obj,SpanName) {
var curDateTime = new Date(); //For IE
var poststr = "name=" + encodeURI( document.getElementById("name").value ) +
"&email=" + encodeURI( document.getElementById("email").value ) +
"&uniqueID=" + curDateTime +
"&msg=" + encodeURI( document.getElementById("msg").value ) ;
var SpanName = SpanName;
//alert (SpanName);
makePOSTRequest('Process.php', poststr, SpanName);
}


</script>
<!------------------------------------------------ END AJAX CODE ---------------------------------->

</head>
<body>
<table width="316" border="0" cellpadding="4" cellspacing="0" class="blueBorder">
<tr>
<td colspan="2" class="title1"><a href="http://www.nabeelakhtar.net">Tutorials @ NabeelAkhtar.NET</a><a href="http://www.nabeelakhtar.net"></a> </td>
</tr>
<tr>
<td width="141" class="title1">AJAX Contact Form </td>
<td width="157" class="orange">Status: <span class="greenBold" id="status">Ready</span> </td>
</tr>
</table>
<span id="ContactFormSpan">
<table width="316" border="0" cellpadding="4" cellspacing="0" class="blueBorder">
<form action="javascript:Contact(document.getElementById('ContactForm'),'ContactFormSpan'); show_hint('Sending Data, Please Wait...', 'status');" method="post" name="ContactForm" id="ContactForm">

<tr>
<td width="141" align="right" class="normal">Name:</td>
<td width="157"><input name="name2" type="text" class="inputBlack" id="name" size="20" maxlength="50" /></td>
</tr>
<tr>
<td align="right" class="normal">Email:</td>
<td><input name="email2" type="text" class="inputBlack" id="email" size="20" maxlength="50" /></td>
</tr>
<tr>
<td align="right" class="normal">Message:</td>
<td><input name="msg2" type="text" class="inputBlack" id="msg" size="20" maxlength="50" /></td>
</tr>
<tr>
<td align="right" class="normal">&nbsp;</td>
<td><input name="Submit2" type="submit" class="buttonBlue" value="Submit" /></td>
</tr>
<tr>
<td colspan="2" align="left" class="normal">Note: This is a demo form. This form will NOT send out emails. </td>
</tr>

</form>
</table>
</span>
</body>
</html>

Following is the code for the "Process.php" file:
<?php
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$msg = stripslashes($_POST['msg']);
echo "
<table width=\"316\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\" class=\"blueBorder\">
<tr>
<td align=\"left\" class=\"title1\">Your Information has been processed</td>
</tr>
<tr>
<td align=\"left\" class=\"normal\">Name: $name <br> Email: $email <br> Message: $msg</td>
</tr>
<tr>
<td align=\"left\" class=\"normal\">Note: This is a demo form. This form will NOT send out emails. </td>
</tr>
<tr>
<td align=\"left\" class=\"normal\"><a href=Form.php>Try Again</a></td>
</table>";
?>


Building Chat Application Using C# Part 1 --Building chat Client--

  Download the Chat Client Application project (Visual Studio 2005)



In this two part tutorial you will learn how to create a chat client that connects to a chat server and exchanges messages with all the other connected clients. The first part covers the development of the client application.

» C# Chat: Part 1 - Building the Chat Client (currently reading)
» C# Chat: Part 2 - Building the Chat Server 

Building a Chat Server and a Chat Client 
To no avail I've been searching the web for a good C# chat client/server application that is not thousands of lines of code long. The only simple ones I could find were flawed or very buggy, but then again I tried to combine the good parts of all the tutorials I found into one application, and one tutorial that you can see here today. We are going to build a fairly larger application (a few hundred lines of codes) than the ones we're used to here on Geekpedia, but we're still going to keep it simple. In fact, there will be two applications: one is a chat server, that handles incoming connections, stores them in hash tables, and distributes new messages to everyone connected, and the other is of course, the chat client, which connects to the server, sends messages and listens for incoming messages. A little knowledge of C#'s networking objects, multi-threading, events and delegates will definitely help you understand this tutorial more easily. A good way to start learning about delegates, events and creating client-server applications is to read the Delegates and Events in C# tutorial first.
The chat server will be able to accept as many chat clients as allowed by the hash table (and you are able to define the limit of the hash table yourself), and it will also track all the messages that are going back and forth in its own chat window, so you should be able to scale this code to a full blown chat application as long as you add the necessary error handling and the bells and whistles.  

The client application

The client application is, as you might have expected, the simpler one, since all it has to do is to attempt to connect to the chat server, request an username, start listening for messages and sending its own, and finally disconnecting.
Start Visual Studio 2005 and create a new C# Windows Application. I've given mine the obvious "Chat Client" name.
The first two TextBoxes (txtIp and txtUser) will hold the IP address of the server we want to connect to and the desired username. Before testing out this code keep in mind to change this IP address to the one of the computer in your network that runs the client. If you read the Delegates and Events in C# tutorial, you probably assume you can run the chat application and the server application on the same machine, without needing two different computers connected through a network or the Internet. And you would be right.
The Connect (btnConnect) and Send (btnSend) buttons are obvious, they're for connecting to the server and sending messages. The large multi-line TextBox is named txtLog and it is where all the messages will be shown.The small TextBox at the bottom is called txtMessage and it is where the message to be sent to the server will be typed.
Now that we're done with the actual design of the form, we can finally code. Since we will be making use of networking, streaming and threading objects, start by adding the following using statements:


using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;

We're going to declare most of our objects inside the class, as private, since we don't need them accessible from anywhere else outside the class:

/ Will hold the user name
private string UserName = "Unknown";
private StreamWriter swSender;
private StreamReader srReceiver;
private TcpClient tcpServer;
// Needed to update the form with messages from another thread
private delegate void UpdateLogCallback(string strMessage);
// Needed to set the form to a "disconnected" state from another thread
private delegate void CloseConnectionCallback(string strReason);
private Thread thrMessaging;
private IPAddress ipAddr;
private bool Connected;

And now that we have them declared, let's put them to use. Let's start with the btnConnect_Click event which can be automatically generated if you double click on the Connect button. Inside it we're going to check whether or not we are connected to a server. If we are, we should call the method that initializes the connection, otherwise we call the method that closes the connection, also specifying a reason why to it:


private void btnConnect_Click(object sender, EventArgs e)
{
    // If we are not currently connected but awaiting to connect
    if (Connected == false)
    {
        // Initialize the connection
        InitializeConnection();
    }
    else // We are connected, thus disconnect
    {
        CloseConnection("Disconnected at user's request.");
    }
}

All simple so far, so let's move to InitializeConnection():

private void InitializeConnection()
{
    // Parse the IP address from the TextBox into an IPAddress object
    ipAddr = IPAddress.Parse(txtIp.Text);
    // Start a new TCP connections to the chat server
    tcpServer = new TcpClient();
    tcpServer.Connect(ipAddr, 1986);

    // Helps us track whether we're connected or not
    Connected = true;
    // Prepare the form
    UserName = txtUser.Text;

    // Disable and enable the appropriate fields
    txtIp.Enabled = false;
    txtUser.Enabled = false;
    txtMessage.Enabled = true;
    btnSend.Enabled = true;
    btnConnect.Text = "Disconnect";

    // Send the desired username to the server
    swSender = new StreamWriter(tcpServer.GetStream());
    swSender.WriteLine(txtUser.Text);
    swSender.Flush();

    // Start the thread for receiving messages and further communication
    thrMessaging = new Thread(new ThreadStart(ReceiveMessages));
    thrMessaging.Start();
}



Nothing too complicated happens in there. The IP address is parsed from the TextBox into an IPAddress object, and then we open a TCP connection to that address. The port is 1986 but it makes no difference as long as its free. We then prepare the controls on the form by disabling some and enabling the others. We also change the caption of btnConnect to now say Disconnect. Through a stream, we then tell the server which username we want, and immediately after that we start a new thread that calls the method ReceiveMessages() which will listen for incoming messages from now on. By putting this in a separate thread, our application is still fully usable while it is listening for messages from the server and keeping the connection alive.

It's time to see what the ReceiveMessages() method is all about:

private void ReceiveMessages()
{
    // Receive the response from the server
    srReceiver = new StreamReader(tcpServer.GetStream());
    // If the first character of the response is 1, connection was successful
    string ConResponse = srReceiver.ReadLine();
    // If the first character is a 1, connection was successful
    if (ConResponse[0] == '1')
    {
        // Update the form to tell it we are now connected
        this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { "Connected Successfully!" });
    }
    else // If the first character is not a 1 (probably a 0), the connection was unsuccessful
    {
        string Reason = "Not Connected: ";
        // Extract the reason out of the response message. The reason starts at the 3rd character
        Reason += ConResponse.Substring(2, ConResponse.Length - 2);
        // Update the form with the reason why we couldn't connect
        this.Invoke(new CloseConnectionCallback(this.CloseConnection), new object[] { Reason });
        // Exit the method
        return;
    }
    // While we are successfully connected, read incoming lines from the server
    while (Connected)
    {
        // Show the messages in the log TextBox
        this.Invoke(new UpdateLogCallback(this.UpdateLog), new object[] { srReceiver.ReadLine() });
    }
}

A new stream reader is hooked up to the TCP client. It will listen for incoming messages. But first of all, we read the first line coming from the server. The reason for that is that we know the first line contains a response telling us whether or not we connected successfully. Two reasons why we might've not connected successfully are if we attempted to use an username that is already taken, or if we attempted to use Administrator as the username, which is reserved for obvious purposes. The first character of the response given by the server tells us through a 1 that the connection was successful, and through a 0 if it was unsuccessful. And in that case, it also reads a reason as to why it was unsuccessful. That reason starts at the 3rd character of the message, since the first one is the number, and the second one is a pipe character. For example: 0|Username is already in use. Now you can see why if the first character is not a 1 we read the string that starts at the 3rd character and ends at the end of the line.

The this.Invoke() calls tell the form to update itself. We can't directly update the form elements ourselves from this method because it's in a separate thread (remember we called it using ThreadStart()) and cross-thread operations are illegal.

Finally, the while (Connected) loop keeps calling the srReceiver.ReadLine() method which checks for incoming messages from the server.

Next comes the method that we kept calling using this.Invoke() - all it does is to update the txtLog TextBox with the latest message:
// This method is called from a different thread in order to update the log TextBox
private void UpdateLog(string strMessage)
{
    // Append text also scrolls the TextBox to the bottom each time
    txtLog.AppendText(strMessage + "\r\n");
}
So far we've seen how to receive messages from the server, but nothing about how to send them. When do we want to send a message? When the Send button is clicked or when the Enter key is pressed while txtMessage has the focus. This should be hooked up to the Click event of the btnSend button:


// We want to send the message when the Send button is clicked
private void btnSend_Click(object sender, EventArgs e)
{
    SendMessage();
}

And this needs to be hooked up to the KeyPress event of txtMessage:
// But we also want to send the message once Enter is pressed
private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)
{
    // If the key is Enter
    if (e.KeyChar == (char)13)
    {
        SendMessage();
    }
}

You can see that both of them make a call to SendMessage, which we are going to see next:
// Sends the message typed in to the server
private void SendMessage()
{
    if (txtMessage.Lines.Length >= 1)
    {
        swSender.WriteLine(txtMessage.Text);
        swSender.Flush();
        txtMessage.Lines = null;
    }
    txtMessage.Text = "";
}
 Quite simple, isn't it? It just checks for the number of lines to be greater or equal to 1, and then writes that line to the TCP connection through the StreamWriter object. Calling Flush() ensures that the messages are being sent right away.

We seem to be almost done with the client application. But let's not forget that when btnConnect was clicked, if we were already connected, we called a method called CloseConnection() - what happened to that? Well here it is:
// Closes a current connection
private void CloseConnection(string Reason)
{
    // Show the reason why the connection is ending
    txtLog.AppendText(Reason + "\r\n");
    // Enable and disable the appropriate controls on the form
    txtIp.Enabled = true;
    txtUser.Enabled = true;
    txtMessage.Enabled = false;
    btnSend.Enabled = false;
    btnConnect.Text = "Connect";

    // Close the objects
    Connected = false;
    swSender.Close();
    srReceiver.Close();
    tcpServer.Close();
}
The form is being brought back to the not-connected state, and the TCP connection and streams are being closed. But what happens if the user doesn't click Disconnect and just closes the application while the connection with the server is alive? We surely don't want to leave the connection open like this till it dies by its own. Thankfully there is the ApplicationExit event that fires when the application closes, and that's where we can close our connection. To hook up the event change your Form1 constructor to the following:
public Form1()
{
    // On application exit, don't forget to disconnect first
    Application.ApplicationExit += new EventHandler(OnApplicationExit);
    InitializeComponent();
}


And here is the event handler that does the actual disconnection:

// The event handler for application exit
public void OnApplicationExit(object sender, EventArgs e)
{
    if (Connected == true)
    {
        // Closes the connections, streams, etc.
        Connected = false;
        swSender.Close();
        srReceiver.Close();
        tcpServer.Close();
    }
}
Believe or not, we're done with the chat client application. You should be able to compile and run it now, but of course there's nothing to connect to because we haven't developed the server. But that comes next in C# Chat: Part 2- Building the Chat Server. Here's a little teaser of our applications in action, with the server in the shadow of the two:
 See you sooner with C# Chat: Part 2- Building the Chat Server


Delegates and Events in C#


This C# tutorial will teach you how to create delegates and events in C# using a practical example of creating two applications, a client and a multi-threaded server. You will learn how to fire your own custom event from a class and handle it in a different class.

Event firing and handling

The scope of this tutorial is to teach you how to create your own events, fire them and handle them. If you done any C# programming you're sure to have used events already. The click of a button, the loading of the form, all these are events that are coded into the .NET Framework. However when you create your own classes, many times you'll find it necessary to create your own events. For taking full advantage of this tutorial it's best that you know at least the basics of object oriented programming in C#, such as classes, constructors, properties, instantiation, etc. Also if you know anything about working with threads, it will help.

In this tutorial we're going to create a real-life application, or at least the start of a real-life application. It will consist of two projects: a client and a server. The client application connects to the server application through TCP IP. These two applications could connect to each other through a network or through the Internet. As long as the port specified is the same in both applications (and the firewall doesn't block it), and if you specified the correct IP addresses, everything will work just fine. But where do the delegates and events come into play? In the server application. There we will have a class that listens for connections. When a client is accepted, we want an event to be fired. This event should be handled in the class that displays the form, so that we can show a message box.

Let's start by creating the client application, which has very little code to it.


The client application

Start Visual Studio 2005 and create a new C# Windows Application. I called mine "LilClient":
This is what our client application looks like. A TextBox and a Button btnConnect. The TextBox is named txtIp and it will store the IP address of the server that we want to connect to. Obviously this depends on where you'll run your server application. You could run it on the very same computer as the client application. However most important is that the IP address is the one of your machine, if you're going to run the client and the server on the same machine, or in a network, you should use the computer's network IP. Many times this is 192.168.0.1 however in my network it is 192.168.1.101. You can find the list of IP addresses that your computer uses by doing an ipconfig command at the MS-DOS command prompt.

First thing to do in this Windows Application is to add this using statement:


using System.Net.Sockets;


Double click the btnConnect button and you'll get to its Click event (speaking of events, eh!); inside add the following code:


private void btnConnect_Click(object sender, EventArgs e)
{
    // Create a new TCP client
    TcpClient tcpServer = new TcpClient();
    // Connect it to the specified IP address and port
    tcpServer.Connect(txtIp.Text, 1986);
    // Close the connection
    tcpServer.Close();
}
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"exception if the IP address you have entered is incorrect.
Next comes the server application where we're going to get into the real scope of this tutorial: delegates and custom events.


The server application

Start a new C# project. I gave mine a more serious name this time: "CustomEventsAndDelegates" - sounds classy, doesn't it?
The form is very similar to the one of the client: we have our txtIp TextBox, a btnStart Button and a lblStatus Label. Switch to code view and since we'll be using the IPAddress object in this class, add the following:


using System.Net;


Now double click the Start Server button to get to its Click event where you'll use the following code:


private void btnStart_Click(object sender, EventArgs e)
{
    // Parse the IP address from the textbox into an IPAddress object
    IPAddress ipAddr = IPAddress.Parse(txtIp.Text);
    // Create a new instance of the Monitor class and pass the IP address to the constructor
    Monitor myMonitor = new Monitor(ipAddr);
    // Bind the event to an event handler
    myMonitor.StatusChangedEvent += new StatusChangedHandler(myMonitor_StatusChanged);
    // Call the method that starts monitoring for connections
    myMonitor.StartMonitoring();
    // Let the user know
    lblStatus.Text = "Monitoring for connections...";
}
So what's happening here? First we simply create an IPAddress object where we store the IP address in the Text Box. Now I should tell you that the IP address in the TextBox is the IP address of the server, and since a server can have multiple network devices and IP addresses, we don't know which one should be used. Thus, the IP address should be typed in The IP address should be the same one as the one that's entered in the client application.

What's the deal with the Monitor object? What namespace is that? Well that's the class we're going to create next. The main purpose of this class is to monitor for incoming connections from client applications. It will have a constructor that takes an IPAddress object, and that's why we pass the IP address to it when initializing the myMonitor object.

The next line is most interesting. That's where we bind the event that we're going to create very soon to an event handler. You can see that the event handler's name is myMonitor_StatusChanged, remember this because we're having a look at it in a second.

The last two lines are self explanatory: a method to start monitoring is called on the myMonitor object, and a label on the form is updated.

There's only one piece of code left in this class and that is the event handler:



public void myMonitor_StatusChanged(object sender, StatusChangedEventArgs e)
{
    MessageBox.Show("We got a call from the Monitor class:\r\n" + e.EventMessage, "Message From Server", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

 If you're not familiar with event handlers at all, you should know that this piece of code executes when we fire the event from a different class. If you looked at the Click events of various form objects such as buttons, this must be familiar to you. Only this time the handler is for our own custom event. And another interesting thing to note is that when this event fires, a parameter is passed to it through StatusChangedEventArgs e. This parameter will hold a message sent by the monitoring class, such as "A client has successfully connected!"


Creating and firing your own event

Now we're going to create our final code for this tutorial, but the most important. This is the code that monitors for connections, and when a client does connect, it will fire an event, event which we already handled in the main Form1 class.
In Visual Studio 2005 add a new class file: Monitor.cs. Add the following using statements since we'll be using networks & threads:


using System.Net;
using System.Net.Sockets;
using System.Threading;
 This file will actually contain two classes. One is the Monitor class which we kept talking about but we never seem to get to :-) and the other is the StatusChangedEventArgs class that inherits EventArgs.

Since an event is really a delegate, we need to define a delegate with the signature that we want for the event. Might want to read that twice. For instance we want to pass some arguments - StatusChangedEventArgs, and the only place to define them is in the delegate's signature. So inside Monitor.cs and the namespace, but not inside the class, put the following line:


public delegate void StatusChangedHandler(object sender, StatusChangedEventArgs e);
Now that we know how the event will look like, thanks to the delegate signature, we need to define what arguments StatusChangedEventArgs will contain. First we need some way to set these arguments, because they're being passed useless if we don't set them to a value. And that's why we need a constructor. Of course, we also want to retrieve the arguments out of StatusChangedEventArgs so we need a property. All these will be defined into a class named StatusChangedEventArgs. you should put it in the Monitor.cs file:


public class StatusChangedEventArgs : EventArgs
{
    // This will store our only parameter / event argument, which is the event message
    private string EventMsg;

    // We need to define this property in order to retrieve the message in the event handler, back in Form1.cs
    public string EventMessage
    {
        get
        {
            return EventMsg;
        }
    }

    // The constructor will set the message
    public StatusChangedEventArgs(string strEventMsg)
    {
        EventMsg = strEventMsg;
    }
}
 So we have the arguments defined, we can set and retrieve them. Inside Monitor.cs we should now deal with the Monitor class for which we created the file in the first place. And finally here it is, in all its glory, our Monitor class:


class Monitor
{
    // Will store the IP address passed to it
    IPAddress ipAddress;

    // The constructor sets the IP address to the one retrieved by the instantiating object
    public Monitor(IPAddress address)
    {
        ipAddress = address;
    }

    // Declare the event that we'll fire later
    public event StatusChangedHandler StatusChangedEvent;
    // The thread that will hold the connection listener
    private Thread thrListener;
    // The TCP object that listens for connections
    private TcpListener tlsServer;
    // The thread that will send information to the client
    private Thread thrSender;
    // Will tell the while loop to keep monitoring for connections
    bool ServRunning = false;

    public void StartMonitoring()
    {
        // Get the IP of the first network device, however this can prove unreliable on certain configurations
        IPAddress ipaLocal = ipAddress;
        if (tlsServer == null)
        {
            // Create the TCP listener object using the IP of the server and the specified port
            tlsServer = new TcpListener(ipaLocal, 1986);
        }
        // Start the TCP listener and listen for connections
        tlsServer.Start();

        // The while loop will check for true in this before checking for connections
        ServRunning = true;

        // Start the new tread that hosts the listener
        thrListener = new Thread(KeepListening);
        thrListener.Start();
    }

    private void KeepListening()
    {
        TcpClient tclServer;
        // While the server is running
        while (ServRunning == true)
        {
            // Accept a pending connection
            tclServer = tlsServer.AcceptTcpClient();
            // Start a new thread where our new client who just connected will be managed
            thrSender = new Thread(new ParameterizedThreadStart(AcceptClient));
            // The thread calls the AcceptClient() method
            thrSender.Start(tclServer);
        }
    }

    // Occures when a new client is accepted
    private void AcceptClient(object newClient)
    {
        // Set the argument/parameter to a message explaining what just happened
        StatusChangedEventArgs evArg = new StatusChangedEventArgs("A client was successfully accepted.");
        // Fire the event because a new client was accepted
        StatusChangedEvent(this, evArg);
    }
}
 With the comments it's pretty much self explanatory. There's a method that starts the monitoring, one that does the listening, and finally one that accepts a client. Technically it doesn't do anything with the client connection, it just lets the main form know that a client has connected successfully, which was the main purpose of this tutorial all along.

Now that wasn't that hard, was it? If you run both applications and most importantly, input the correct IP addresses, you should get a message on the server application once you connect the client to it. And behind that, which looks like a very simple task to accomplish, you'll know that a lot of stuff really happens, an event defined by the signature of a delegate fires from a class, and with it carries the parameters defined in another class. The event is handled in the class that holds the form, which shows the message box. Here's the entire process:

 P.S.: If when you run your client application you get an alert from the Windows Firewall or any other firewall for that matter, don't forget to unblock the application:


 cccc

Professional website design and uncut using Photoshop and Dreamweaver


Today we Give you a modest lesson  To design  website in photoshop.
 Lesson Requirements:
1 - Adobe Photoshop and Photoshop experience is simple. Get It Now!!
2 - Adobe Dreamweaver .
Get It Now!!
Lesson annotated a video lesson demonstrates the process of design and cutting, as well as conversion to the web page and all this  Adobe photoshop.

we need   previous programs in order to adjust the alignment of the site as well as the development background of the website has been commentary on Adobe Dreamweaver
 

This will be the final outcome of the site in this lesson
                                                               Click here to View

                                  Download Lesson


.

Friday, January 28, 2011

Facebook has become the third most visited site in the world

The latest visitor figures for the Web published by comScore, in November, Facebook has become the third most visited site in the world. With nearly 648 million unique visitors, the social network remains behind Google (970 million) and Microsoft (869 million). But it goes beyond Yahoo and its 630 million unique visitors, while in October the two sites were still on a par to 633 million.

In one year Facebook has won more than 200 million unique visitors per month

In early December, the CEO of Yahoo, Carol Bartz, had sensed the danger, pointing Facebook as its biggest rival to Google. Facebook, now No. 4 just last eighteen months, a year ago totaled just over 400 million visitors, when Yahoo attracted more than 600. United States, however, Yahoo still leads with 181 million unique visitors, ahead of Google (178.7), Microsoft (175.7) and Facebook (151.7). But Facebook will now capturing a quarter of market banners, twice as Yahoo. And he would pass for viewing Yahoo videos by becoming the second U.S. site behind Google.
    source src=latribune.fr