Engineersstuff

Your Ad Here Your Ad Here

November 24, 2009

Introduction

Filed under: PHP

scripting language like ASP but its open source software  that helps make webpages more interactive, by allowing them to do more things.

For example, a website programmed with PHP can have pages that are password protected, whereas a website with no programming can not do this.

Standard PHP file extensions are: .php .php3 or .phtml, although you can tell a webserver to use any extension.

Its structure was influenced by many languages like C, Perl, Java, C++, and even Python.

It is considered to be free software by mean of the Free Software Foundation.And is free to download and use.

The newest version of PHP is 5.3.1, released on 19 November 2009.

July 16, 2008

Did You Know…

Filed under: General


The first tool for searching the Internet, created in 1990, was called "Archie". It downloaded directory listings of all files located on public anonymous FTP servers; creating a searchable database of filenames. A year later "Gopher" was created. It indexed plain text documents. "Veronica" and "Jughead" came along to search Gopher’s index systems. The first actual Web search engine was developed by Matthew Gray in 1993 and was called "Wandex". [Source ]

 

Web Browser in Java

Filed under: Projects

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;

public class WebBrowser
{
    public static void main(String [] args)
    {
        JFrame frame = new EditorPaneFrame();
        frame.show();
    }
}
class EditorPaneFrame extends JFrame
{

    private JTextField url;
    private JCheckBox editable;
    private JButton loadButton;
    private JButton backButton;
    private JEditorPane editorPane;
    private Stack urlStack = new Stack();

    public EditorPaneFrame()
    {
        setTitle("Java Web Browser");
        setSize(600,400);
        addWindowListener(new WindowAdapter()
        {
            public void windowClosing(WindowEvent e)
            {
                System.exit(0);
            }
        } );

        // set up text field and load button for typing in URL

        url = new JTextField(30);

        loadButton = new JButton("Load");
        loadButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                try
                {
                    // remember URL for back button
                    urlStack.push(url.getText());
                    editorPane.setPage(url.getText());
                }
                catch(Exception e)
                {
                    editorPane.setText("Error: " +e);
                }
            }
        });

        // set up back button and button action

        backButton = new JButton("Back");
        backButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                if(urlStack.size()<=1) return;
                try
                {
                    urlStack.pop();
                    String urlString = (String)urlStack.peek();
                    url.setText(urlString);
                    editorPane.setPage(urlString);
                }
                catch(IOException e)
                {
                    editorPane.setText("Error : " +e);
                }
            }
        });

        editorPane = new JEditorPane();
        editorPane.setEditable(false);
        editorPane.addHyperlinkListener(new HyperlinkListener()
        {
            public void hyperlinkUpdate(HyperlinkEvent event)
            {
                if(event.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                {
                    try
                    {
                        urlStack.push(event.getURL().toString());
                        url.setText(event.getURL().toString());

                        editorPane.setPage(event.getURL());
                    }
                    catch(IOException e)
                    {
                        editorPane.setText("Error: " + e);
                    }
                }
            }
        });

        editable = new JCheckBox();
        editable.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent event)
            {
                editorPane.setEditable(editable.isSelected());
            }
        });

        Container contentPane = getContentPane();
        contentPane.add(new JScrollPane(editorPane), "Center");

        JPanel panel = new JPanel();
        panel.add(new JLabel("URL"));
        panel.add(url);
        panel.add(loadButton);
        panel.add(backButton);
        panel.add(new JLabel("Editable"));
        panel.add(editable);

        contentPane.add(panel,"South");
    }

}

Server and Client In Java

Filed under: Projects

//Server.java
import java.net.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Server extends JFrame
{
JTextField txtenter;
JTextArea txtadisplay;
ObjectOutputStream output;
ObjectInputStream input;
public Server()
{
 super("SERVER");
 Container c=getContentPane();

 txtenter=new JTextField();
 txtenter.setEnabled(false);
 txtenter.addActionListener(
 new ActionListener(){
  public void actionPerformed(ActionEvent e)
  {
    sendData(e.getActionCommand());
  }
 }
 );
 c.add(txtenter,BorderLayout.SOUTH);

 txtadisplay=new JTextArea();
 txtadisplay.setEditable(false);
 c.add(new JScrollPane(txtadisplay),BorderLayout.CENTER);

 setSize(300,150);
 show();
}
public void runServer()
{
 ServerSocket ss;
 Socket s;
 int counter = 1;

 try
 {
   //create a seversocket
  ss=new ServerSocket(5000,100);

  while(true)
  {

    //wait for the connection
   txtadisplay.setText("Waiting for the Connection…");

    //establishing connection
   s=ss.accept();
   txtadisplay.append("
Conection "+counter+"received
from:"+s.getInetAddress().getHostName());

    //getting input/output
   output=new ObjectOutputStream(s.getOutputStream());
   output.flush();

   input=new ObjectInputStream(s.getInputStream());

    //processing connection
   String message="Server>>>Conection Sucessfull…";
   output.writeObject(message);
   output.flush();
   txtenter.setEnabled(true);

   do
   {
    message=(String) input.readObject();
    txtadisplay.append("
"+message);
    txtadisplay.setCaretPosition(txtadisplay.getText().length());
   }while(!message.equals("CLIENT>>>TERMINATE"));

   txtadisplay.append("
User Terminated Connection…");
   output.close();
   input.close();
   s.close();
   ++counter;
  }
 }
 catch(Exception e)
 {

 }
}
public void sendData(String s)
{
 try
 {
  output.writeObject("SERVER>>>"+s);
  txtadisplay.append("
SERVER>>>"+s);
 }
 catch(Exception e)
 {

 }
}
public static void main(String args[])
{
 Server ser=new Server();

 ser.addWindowListener(
 new WindowAdapter(){
 public void WindowClosing(WindowEvent e)
 {
  System.exit(0);
 }
 }
 );
 ser.runServer();
}

}

//Client.java
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Client extends JFrame
{
JTextField txtenter;
JTextArea txtadisplay;
ObjectOutputStream output;
ObjectInputStream input;
String message="";

public Client()
{
 super("CLIENT");
 Container c=getContentPane();

 txtenter=new JTextField();
 txtenter.setEnabled(false);
 txtenter.addActionListener(
 new ActionListener(){
 public void actionPerformed(ActionEvent e)
 {
  sendData(e.getActionCommand());
 }
 });
 c.add(txtenter,BorderLayout.SOUTH);

 txtadisplay=new JTextArea();
 txtadisplay.setEditable(false);
 c.add(new JScrollPane(txtadisplay),BorderLayout.CENTER);

 setSize(300,150);
 show();
}
public void runClient()
{
 Socket s;
 try
 {
   txtadisplay.setText("Attempting Connection…");

    //establishing connection
   s=new Socket("localhost",5000);
   txtadisplay.append("
Connected
to:"+s.getInetAddress().getHostName());

   output=new ObjectOutputStream(s.getOutputStream());
   output.flush();
   input=new ObjectInputStream(s.getInputStream());

   txtenter.setEnabled(true);

    //processing connection
   do
   {
    message=(String)input.readObject();
    txtadisplay.append("
"+message);
    txtadisplay.setCaretPosition(txtadisplay.getText().length());
   }while(!message.equals("SERVER>>>TERMINATE"));
   txtadisplay.append("
Closing Connection…");
   input.close();
   output.close();
   s.close();
}
catch(Exception e)
{}
}
public void sendData(String s)
{
 try
  {
   message=s;
   output.writeObject("CLIENT>>>"+s);
   output.flush();

   txtadisplay.append("
CLIENT>>>"+s);
  }
 catch(Exception e)
 {

 }
}
public static void main(String args[])
{
 Client cli=new Client();

 cli.addWindowListener(
 new WindowAdapter(){
 public void windowClosing(WindowEvent e)
 {
  System.exit(0);
 }
 }
 );
 cli.runClient();

}
}

Multithreaded Server

Filed under: Projects

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

public class MultiThreadedServer
{
    public static void main(String [] args)
    {
        int i=0;
        System.out.println("Server Started. Waiting for connections…");
        try
        {

            ServerSocket s = new ServerSocket(8081);
            for(;;)
            {
                Socket incoming = s.accept();
                System.out.println("New Client Connected with id " + i );
                Thread t = new ThreadedServer(incoming,i);
                i++;
                t.start();
            }
        }
        catch(Exception e)
        {
            System.out.println("Error: " + e);
        }
    }
}

class ThreadedServer extends Thread
{
    Socket incoming;
    int counter;
    public ThreadedServer(Socket i,int c)
    {
        incoming=i;
        counter=c;
    }

    public void run()
    {
        try
        {
            BufferedReader in =new BufferedReader(new InputStreamReader(incoming.getInputStream()));
            PrintWriter out = new PrintWriter(incoming.getOutputStream(), true);

            String line;
            boolean done=false;
            while(!done)
            {
                line=in.readLine();
                if(line.trim().equals("BYE") || line == null)
                    done = true;
                else
                {
                    out.println("Echo Server Responds: " + line);
                    System.out.println("Echo Server Responds: " + line);
                }
            }
            incoming.close();
        }
        catch(Exception e)
        {
            System.out.println("Error: " + e);
        }
    }
}






















BlogUniverse Add to Technorati Favorites Visit blogadda.com to discover Indian blogs Find Blogs in the Blog
Directory Subscribe with Bloglines Blog Directory Who links to my website?
Your Ad Here

Get free blog up and running in minutes with Blogsome
Theme designed by Minz Meyer