hello friends i wrote this coding for personal Messenger

Now we have to create two different class

Class 1 :
Class Name : msgFrame.java
Coding like below

Java Code:
/*
// Created By : 13Guru (Vishal D Paraliya)
// Date : 3-Aug-2010
//-------------------------------------------------------------------------------
// This is a personal messenger we can use this on
// network or internet and its easy to use i have 
// wrote coding just for messenge if you want to
// also share files and something else then tell me
// I will like to help everone....
//-------------------------------------------------------------------------------
// Syntax : java msgFrame <your name>
// Example : java msgFrame 13Guru
// then u get a jframe there was to ways to connect with another 
// client first is to send request to another client 
// and second is to accept the request one client must
// request and second must be accept this is for security 
// so then send messeges to each other 
// Enjoy.... Happy Chating.....
*/
import java.net.*;
import java.rmi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class msgFrame extends JFrame implements ActionListener
{
	//Component Declaration
	
	    private javax.swing.JTextField AccPort;
	    private javax.swing.JLabel IPADD;
	    private javax.swing.JButton btnAccept;
	    private javax.swing.JButton btnSend;
	    private javax.swing.JButton jButton1;
	    private javax.swing.JLabel jLabel1;
	    private javax.swing.JLabel jLabel2;
	    private javax.swing.JLabel jLabel3;
	    private javax.swing.JLabel jLabel4;
	    private javax.swing.JPanel jPanel1;
	    private javax.swing.JPanel jPanel2;
	    private javax.swing.JPanel jPanel3;
	    private javax.swing.JPanel jPanel4;
	    private javax.swing.JScrollPane jScrollPane1;
	    private javax.swing.JScrollPane jScrollPane2;
	    private javax.swing.JTextField reIP;
	    public javax.swing.JTextArea msgArea;
	    private javax.swing.JTextField rePort;
	    public javax.swing.JTextArea sendMsg;
	
	// Variable Declaration

	String ip;
	protected ServerSocket ss;
	protected Socket sk;
	protected static msgFrame mf;
	protected static msgThread mt;
	Thread t;
	public static String myName = null;
	public msgFrame()
	{
		java.awt.GridBagConstraints gridBagConstraints;
		setSize(300,400);
		

	        jPanel1 = new javax.swing.JPanel();
	        jLabel1 = new javax.swing.JLabel();
	        jLabel2 = new javax.swing.JLabel();
	        IPADD = new javax.swing.JLabel();
	        jPanel2 = new javax.swing.JPanel();
	        jScrollPane1 = new javax.swing.JScrollPane();
	        msgArea = new javax.swing.JTextArea();
	        jPanel3 = new javax.swing.JPanel();
	        btnSend = new javax.swing.JButton();
	        jScrollPane2 = new javax.swing.JScrollPane();
	        sendMsg = new javax.swing.JTextArea();
	        jPanel4 = new javax.swing.JPanel();
	        jLabel4 = new javax.swing.JLabel();
	        rePort = new javax.swing.JTextField();
	        jButton1 = new javax.swing.JButton();
	        jLabel3 = new javax.swing.JLabel();
	        AccPort = new javax.swing.JTextField();
	        btnAccept = new javax.swing.JButton();
	        reIP = new javax.swing.JTextField();
	
	        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
	        getContentPane().setLayout(new java.awt.GridBagLayout());
	
	        jPanel1.setLayout(new java.awt.GridBagLayout());
	
	        jLabel1.setText("My Messenger");
	        jPanel1.add(jLabel1, new java.awt.GridBagConstraints());
	
	        jLabel2.setText("IP :");
	        gridBagConstraints = new java.awt.GridBagConstraints();
		gridBagConstraints.gridx = 0;
        	gridBagConstraints.gridy = 1;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        jPanel1.add(jLabel2, gridBagConstraints);

	        IPADD.setText("....");
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 1;
	        gridBagConstraints.gridy = 1;
	        jPanel1.add(IPADD, gridBagConstraints);

	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 0;
        	gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
	        getContentPane().add(jPanel1, gridBagConstraints);

	        jPanel2.setLayout(new java.awt.GridBagLayout());

	        msgArea.setColumns(20);
	        msgArea.setRows(5);
	        msgArea.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        	msgArea.setEnabled(false);
	        jScrollPane1.setViewportView(msgArea);

	        gridBagConstraints = new java.awt.GridBagConstraints();
        	gridBagConstraints.weightx = 0.5;
	        jPanel2.add(jScrollPane1, gridBagConstraints);

	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 1;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
	        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
	        getContentPane().add(jPanel2, gridBagConstraints);
	
	        jPanel3.setLayout(new java.awt.GridBagLayout());
		
	        btnSend.setText("Send");
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 1;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
	        jPanel3.add(btnSend, gridBagConstraints);
	
        	sendMsg.setColumns(20);
        	sendMsg.setRows(5);
        	jScrollPane2.setViewportView(sendMsg);

	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 0;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
	        jPanel3.add(jScrollPane2, gridBagConstraints);

	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 2;
		gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 0);
        	getContentPane().add(jPanel3, gridBagConstraints);

	        jPanel4.setLayout(new java.awt.GridBagLayout());

	        jLabel4.setText("Port");
	        jPanel4.add(jLabel4, new java.awt.GridBagConstraints());
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        gridBagConstraints.weightx = 0.5;
	        jPanel4.add(rePort, gridBagConstraints);

	        jButton1.setText("Send Request");
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 1;
        	gridBagConstraints.gridwidth = 3;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        jPanel4.add(jButton1, gridBagConstraints);

	        jLabel3.setText("Port");
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        jPanel4.add(jLabel3, gridBagConstraints);
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 1;
	        gridBagConstraints.gridy = 2;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        gridBagConstraints.weightx = 0.5;
	        jPanel4.add(AccPort, gridBagConstraints);
	
	        btnAccept.setText("Accept Request");
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 2;
	        gridBagConstraints.gridy = 2;
	        jPanel4.add(btnAccept, gridBagConstraints);
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        jPanel4.add(reIP, gridBagConstraints);
	
	        gridBagConstraints = new java.awt.GridBagConstraints();
	        gridBagConstraints.gridx = 0;
	        gridBagConstraints.gridy = 3;
	        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
	        gridBagConstraints.insets = new java.awt.Insets(1, 0, 0, 0);
	        getContentPane().add(jPanel4, gridBagConstraints);
		
		jButton1.addActionListener(this);
		btnSend.addActionListener(this);
		btnAccept.addActionListener(this);
		try{
			ip = (InetAddress.getLocalHost()).toString();
			IPADD.setText(ip);
		}
		catch(Exception e)
		{}
	}
	public static void main(String arg[])
	{
		myName = arg[0];
		mf = new msgFrame();
		mt = new msgThread(mf);
		mf.setVisible(true);
	}
	public void showMsg(String msg)
	{
		System.out.println("show Message");
		msg = msgArea.getText() + "\n" + msg;
		msgArea.setText(msg);
	}
	public void actionPerformed(ActionEvent ae)
	{
		try{
			if(ae.getSource()==jButton1)
			{
				int port = (new Integer(rePort.getText()).intValue());
				String add = reIP.getText();
				sk = new Socket(add,port);
				ObjectOutputStream oos = new ObjectOutputStream(sk.getOutputStream());
				oos.writeObject("Request Accepted");
				mt.setSocket(sk);
			}
			else
			if(ae.getSource()==btnAccept)
			{
				int port = (new Integer(AccPort.getText()).intValue());
				ss = new ServerSocket(port);
				sk = ss.accept();
				mt.setSocket(sk);
			//	ObjectInputStream ois = new ObjectInputStream(sk.getInputStream());
			//	String msg = (String) ois.readObject(); 
			//	msgArea.setText("ok");
			}
			else
			if(ae.getSource()==btnSend)
			{
				String msg = (String)sendMsg.getText();
				msg = myName + " : " + msg;
				msgArea.setText(msgArea.getText() + "\n" + msg);
				System.out.println(msg);
				ObjectOutputStream oos = new ObjectOutputStream(sk.getOutputStream());
				oos.writeObject(msg);
				sendMsg.setText("");
			}
		}catch(Exception e)
		{}
	}


}
Now we have to create second class
Class 2 :
Class Name : msgThread

Java Code:
import java.net.*;
import java.rmi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;

public class msgThread extends msgFrame implements Runnable
{
	public Socket thsock;
	int l;
	msgFrame mf;
	Thread t;
	// Constructor to Set Class
	public msgThread(msgFrame setmf)
	{
		mf=setmf;
	}
	public void setSocket(Socket sock)
	{
		System.out.println("Socket Setting....");
		thsock = sock;
		//this.run();
		t = new Thread(this,"guru");
		t.start();
		System.out.println("Thread Started");
		
	}
	public void run()
	{
		try{
			l=1;
			System.out.println("Start");
			for(;;)
			{
				System.out.println("Loop Start");
				ObjectInputStream ois = new ObjectInputStream(thsock.getInputStream());
				String msg = (String) ois.readObject(); 
				System.out.println("Thread : " + msg);
				mf.showMsg(msg);
				l++;
				//msg = super.msgArea.getText() + "\n" + msg;
				//super.msgArea.setText("Message"+msg);
				//System.out.println("Loop");
				//Thread.sleep(1000);
				
			}
		}catch(Exception e)
		{}
	}	
}

Now Its time to complie them and now run like below
Syntax : java msgFrame <your name>
Example : java msgFrame 13Guru
then u get a jframe there was to ways to connect with another
client first is to send request to another client
and second is to accept the request one client must
request and second must be accept this is for security
so then send messeges to each other
Enjoy.... Happy Chating.....