Sunday, December 22, 2013

Php Tutorial Part 1 - Run Php Program Locally

In this tutorial guide, We will learn Php step by Step.I hope this tutorial is very helpful to you for learning Php.

The Meaning of Php is HyperText Preprocessor.

Php is server side scripting language that can easily embeded with html.

Most of php syntax like C language.

To write and any php program and check output of written program locally, you have to install wamp or xampp server in your local computer.


First we have to install xampp or wamp server

1> XAMPP Server installation:
    XAMPP IS APACHE FRIEND. xampp is open source project.
   
    First of Download XAMPP server according to tour Operating System like Windows or Linux from http://www.apachefriends.org/en/xampp.html.
and Install It.

    When you are installing xampp you will be asked for path  of Installation.

    After Installing XAMPP, Open XAMPP control Panel and then start Apache and MySql.

    At last, navigate to localhost in webbrowser to ensure correctly install or not.

2> WAMP Server Installation:
    WAMP Server is work only for Windows Operating System.
   
    First Download WAMP Server &Install it.


 WAMP Server Installation Tutorial Video:

WAMP Server Installation Tutorial Video:


Wednesday, June 5, 2013

Java client/server application


AIM: Write a java  that implements a simple client/server application. The client sends data to a server. The server receives the data, uses it to produce a result and then sends the result back to the client. The client displays the result on the console. For ex: The data sent from the client is the numbers and the result produced by the server is the addition of that numbers
Client program:
import java.io.*;
import java.net.*;
public class AddClient
 {
            public static void main(String args[])
             {
                        Socket addSocket = null;
                        DataOutputStream strmToServer = null;
                        DataInputStream strmFromServer = null;
                        final String server = "localhost";
                        int i, currentSum, num;
                        try
                         {
                                    addSocket = new Socket(server, 8000);
                                    strmToServer = new DataOutputStream(addSocket.getOutputStream());
                                    strmFromServer = new DataInputStream(addSocket.getInputStream());
                                    System.out.println("Connected to Server ...");
                        }
                        catch (UnknownHostException ex)
                        {
                                    System.out.println("Unable to find server: " + server);         
                                    System.exit(1);
                        }
                        catch (IOException ex)
                        {
                        System.out.println("Unable to open I/O stream to server: " + server);
                        System.exit(1);
                        }
                        try
                        {
                                    strmToServer.writeInt(args.length-1);
                                    currentSum = Integer.parseInt(args[0]);
                                    for (i=1; i<args.length; i++)
                                    {
                                                num = Integer.parseInt(args[i]);
                                                strmToServer.writeInt(currentSum);
                                                strmToServer.writeInt(num);
                                                currentSum = strmFromServer.readInt();
                                    }
                                    System.out.println("Sum: " + currentSum);
                                    strmFromServer.close();
                                    strmToServer.close();
                                    addSocket.close();
                        }
                        catch (Exception ex)
                        {
                                    ex.printStackTrace();
                         }
            }
}
Server program:

import java.net.*;
import java.io.*;

public class AddServer
 {
            public static void main(String args[])
            {
                        Socket socket = null;
                        ServerSocket serverSocket = null;
                        DataOutputStream strmToClient = null;
                        DataInputStream strmFromClient = null;
                        int i, numAdditions, sum, num1, num2;
                        try
                        {
                                    serverSocket = new ServerSocket(8000);
                                    System.out.println("Server is starting ...");
                        }
                        catch (Exception ex)
                        {
                                    System.out.println("Unable to start server");
                                    System.exit(1);
                        }
                        try
                        {
                                    while (true)
                                    {
                                                socket = serverSocket.accept();
                                                System.out.println("Serving client: " + socket.getInetAddress());
                                                strmToClient = new DataOutputStream(socket.getOutputStream());
                                                strmFromClient = new DataInputStream(socket.getInputStream());
                                                numAdditions = strmFromClient.readInt();
                                                for (i=0; i<numAdditions; i++)
                                                {
                                                            num1 = strmFromClient.readInt();
                                                            num2 = strmFromClient.readInt();
                                                            System.out.println(num1 + " + " + num2);
                                                            sum = num1 + num2;
                                                            strmToClient.writeInt(sum);
                                                }
                                                socket.close();
                                    }
                        }
                        catch (IOException ex)
                        {
                                    System.out.println("Unable to open I/O stream to server: " + ex);
                                    System.exit(1);
                        }
            }
}
Output: