Mybooks

Páginas: 7 (1684 palabras) Publicado: 20 de septiembre de 2012
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author uagrm
*/
import java.net.*;
import java.io.*;
public class Cliente {
public static void main(String[] args)
{
Socket cliente = null;
try
{
cliente = new Socket("127.0.0.1", 1234);
}catch(UnknownHostException uhe)
{

}
catch(IOException ioe)
{

}

if(cliente == null)
System.exit(-1);

DataInputStream in = null;
DataOutputStream out = null;

try
{
in = new DataInputStream(cliente.getInputStream());
out= new DataOutputStream(cliente.getOutputStream());
out.writeUTF("Comando,ON");
out.flush();
}
catch(IOException ioe)
{

}
finally
{
try
{
out.close();
in.close();
cliente.close();
}
catch(Exception e){

}
}
}
}

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
* frmCliente.java
*
* Created on 31-05-2012, 02:35:00 PM
*/
/***
* @author uagrm
*/
public class frmCliente extends javax.swing.JFrame {
Socket cliente;
DataInputStream in = null;
DataOutputStream out = null;
/** Creates new form frmCliente */
public frmCliente() {
initComponents();

try
{
cliente = new Socket("127.0.0.1", 1234);
in = newDataInputStream(cliente.getInputStream());
out = new DataOutputStream(cliente.getOutputStream());
}
catch(UnknownHostException uhe)
{

}
catch(IOException ioe)
{

}
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. Thecontent of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

btON = new javax.swing.JToggleButton();
btOFF = new javax.swing.JToggleButton();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

btON.setText("ON");
btON.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btONActionPerformed(evt);
}
});

btOFF.setText("OFF");
btOFF.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt) {
btOFFActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup()
.addGap(116, 116, 116)
.addComponent(btON)
.addGap(18, 18, 18)
.addComponent(btOFF)
.addContainerGap(166, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)...
Leer documento completo

Regístrate para leer el documento completo.

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS