⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 broadcast.java

📁 飞鸽传书的源代码 快速的局域网传输软件
💻 JAVA
字号:
/*
 * BroadCast.java
 *
 * Created on 2007年7月1日, 下午5:04
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package trans;

/**
 *
 * @author 鹏飞
 */
import java.util.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class BroadCast implements  Runnable
{
       private InetAddress address;
       private char op;
       private String mes;
       public BroadCast(char op,InetAddress address,String mes)
       {
           this.address = address;
           this.op = op;
           this.mes = mes;
       }
	public void run()
	{
		String newStr = "";
                if(op == 'S' || op == 'R' || op == 'M' || op == 'A')
                {
                     newStr += op;
                     newStr += mes;
                 }
                else 
                {
                     JOptionPane.showMessageDialog(null,"无该操作!","错误", JOptionPane.ERROR_MESSAGE);
                    return;
                 }
            try{
                    DatagramSocket clientSocket = new DatagramSocket();
                    byte data[] = newStr.getBytes("UTF-8");
                    DatagramPacket theOut = new DatagramPacket(data,data.length,address,2007);
                    clientSocket.send( theOut );
                    clientSocket.close();
                }
            catch (Exception e)
            {
                 JOptionPane.showMessageDialog(null, e.getMessage() + this.getClass ().toString (),"错误", JOptionPane.ERROR_MESSAGE);
            }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -