how to get ActionEvent on client -fired on server.

hi,

I wanna to develop screen capture software.

Here i have server running and listening for clients... and one button called " CAPTURE " and listBox for online clients through we can capture desktop of that IP machine.

and client is running on perticular host.

now when i click on server window's CAPTURE button.

how can i get that event on client's program through SOCKET ?

please give code for that....

i have tried but failed

following is my code ;

client code

package clientPack;

import java.awt.*;

import java.util.*;

import java.io.*;

import java.net.*;

publicclass CaptureClientextends javax.swing.JFrame{

/** Creates new form CaptureClient */

InetAddress host;

public CaptureClient()

{

super("Capture Client");

initComponents();

}

publicvoid ConnectToServer()

{

try

{

host = InetAddress.getLocalHost();

ClientInfo.setText(host.getHostAddress());//+ "::" + host.getHostAddress());

Socket s =new Socket("127.0.0.1", 9999);

BufferedReader r =new BufferedReader(new InputStreamReader(s.getInputStream()));

PrintWriter w =new PrintWriter(s.getOutputStream(),true);

BufferedReader con =new BufferedReader(new InputStreamReader(System.in));

ClientStatus.setText("Server Connected..");

String line;

}

catch (Exception err)

{System.err.println(err);}

}

publicvoid run()

{

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

privatevoid initComponents(){

jLabel1 =new javax.swing.JLabel();

jLabel2 =new javax.swing.JLabel();

ClientStatus =new javax.swing.JLabel();

jLabel3 =new javax.swing.JLabel();

ClientInfo =new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setResizable(false);

jLabel1.setText("CLIENT");

jLabel2.setText("Status :");

ClientStatus.setText("status");

ClientStatus.setDoubleBuffered(true);

ClientStatus.setEnabled(false);

jLabel3.setText("Client Info :");

ClientInfo.setFont(new java.awt.Font("Arial", 0, 12));

ClientInfo.setText("ClientInformation");

org.jdesktop.layout.GroupLayout layout =new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(191, 191, 191)

.add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 43, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(layout.createSequentialGroup()

.add(26, 26, 26)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 69, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(ClientInfo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 249, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(layout.createSequentialGroup()

.add(jLabel2)

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)

.add(ClientStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 311, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))

.addContainerGap())

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(19, 19, 19)

.add(jLabel1)

.add(11, 11, 11)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel3)

.add(ClientInfo))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 29, Short.MAX_VALUE)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)

.add(jLabel2)

.add(ClientStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(28, 28, 28))

);

pack();

}// </editor-fold>

/**

* @param args the command line arguments

*/

publicstaticvoid main(String args[])

{

CaptureClient cc=new CaptureClient();

SystemTrayTest stray=new SystemTrayTest();

//cc.setVisible(true);

cc.ClientStatus.setForeground(Color.RED);

cc.ConnectToServer();

}

// Variables declaration - do not modify

private javax.swing.JLabel ClientInfo;

private javax.swing.JLabel ClientStatus;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

// End of variables declaration

}

server code

package serverPack;

import java.net.*;

import java.awt.*;

import java.util.*;

import java.io.*;

/*

* CaptureServer.java

*

* Created on September 19, 2006, 2:39 PM

*/

/**

*

* @author abc

*/

publicclass CaptureServerextends javax.swing.JFrameimplements Runnable

{

//String host,ip;

Vector ipVector;

int portnum=9999;

ServerSocket serverSocket =null;

Socket clientSocket =null;

/** Creates new form CaptureServer */

public CaptureServer()

{

super("CAPTURE SERVER");

initComponents();

}

publicvoid ConnectClient()

{

try{

StatusLabel.setText("Wait for Client Connection ...");

serverSocket =new ServerSocket(portnum);

}catchServerBox.setColumns(20);

ServerBox.setRows(5);

ServerBox.setDoubleBuffered(true);

jScrollPane1.setViewportView(ServerBox);

org.jdesktop.layout.GroupLayout layout =new org.jdesktop.layout.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(19, 19, 19)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(StatusLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)

.add(jLabel1)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 362, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.add(19, 19, 19))

.add(layout.createSequentialGroup()

.add(158, 158, 158)

.add(CapButton)

.addContainerGap(169, Short.MAX_VALUE))

.add(layout.createSequentialGroup()

.add(170, 170, 170)

.add(FixSERVER)

.addContainerGap(192, Short.MAX_VALUE))

);

layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.add(20, 20, 20)

.add(FixSERVER)

.add(18, 18, 18)

.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.add(18, 18, 18)

.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)

.add(layout.createSequentialGroup()

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

.add(CapButton)

.add(25, 25, 25))

.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()

.add(24, 24, 24)

.add(jLabel1)

.add(16, 16, 16)))

.add(StatusLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

/**

* @param args the command line arguments

*/

publicstaticvoid main(String args[])

{

CaptureServer cs =new CaptureServer();

cs.setVisible(true);

cs.StatusLabel.setForeground(Color.RED);

cs.StatusLabel.setText("Ready ...");

cs.ConnectClient();

}

// Variables declaration - do not modify

private javax.swing.JButton CapButton;

private javax.swing.JLabel FixSERVER;

private javax.swing.JTextArea ServerBox;

private javax.swing.JLabel StatusLabel;

private javax.swing.JLabel jLabel1;

private javax.swing.JScrollPane jScrollPane1;

// End of variables declaration

}

(IOException e){ System.err.println("Could not listen on port:" + portnum);}

while(true){

try{

System.out.println("Waiting for client connection");

clientSocket = serverSocket.accept();

System.out.println("Creating new thread to handle request");

StatusLabel.setText("Client Connected ...");

clientSocket.getRemoteSocketAddress();

ipVector.add(clientSocket);

ServerBox.setText("Client :"+ipVector);

System.out.println("Client Added to Server List");

new MyThread(clientSocket).start();

}catch (IOException e){

System.err.println("Accept failed.");

System.exit(1);

}

}

}

publicvoid run()

{

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

// <editor-fold defaultstate="collapsed" desc=" Generated Code ">

privatevoid initComponents(){

FixSERVER =new javax.swing.JLabel();

CapButton =new javax.swing.JButton();

StatusLabel =new javax.swing.JLabel();

jLabel1 =new javax.swing.JLabel();

jScrollPane1 =new javax.swing.JScrollPane();

ServerBox =new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setAlwaysOnTop(true);

setFont(new java.awt.Font("BankGothic Lt BT", 1, 10));

setResizable(false);

FixSERVER.setText("SERVER");

CapButton.setText("Capture");

jLabel1.setText("Status :");

[15827 byte] By [Ghanshyama] at [2007-10-3 5:19:17]
# 1

>

> and client is running on perticular host.

> now when i click on server window's CAPTURE button.

> how can i get that event on client's program through

> SOCKET ?

The server sends a message to the client.

The client gets that message.

The client processes that message ('capture the screen')

The client packages the result and sends it back to the server as a message.

jschella at 2007-7-14 23:26:12 > top of Java-index,Core,Core APIs...