msgdaemonserver.java

来自「局域网聊天工具,学习java桌面应用程序的好例子,(代传)」· Java 代码 · 共 61 行

JAVA
61 行
字号
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package ipmsg.network;import ipmsg.etc.Command;import ipmsg.etc.GlobalConstant;import ipmsg.etc.GlobalVar;import java.io.IOException;import java.net.DatagramPacket;import java.net.SocketException;/** * * @author qqiu */public class MsgDaemonServer extends Thread {    public MsgDaemonServer() {        /*try {            UtilityNet.msgSocket =                    new DatagramSocket(GlobalConstant.IPMSG_DEFAULT_PORT);        } catch (SocketException ex) {        }*/    }    @Override    public void run() {        try {            byte[] buf = new byte[GlobalConstant.COMMAND_LEN];            DatagramPacket recv = new DatagramPacket(buf, buf.length);            Command tmpCom;            while (true) {                UtilityNet.msgSocket.receive(recv);                                if(GlobalVar.BLACK_LIST.contains(                        recv.getAddress().getHostAddress()))continue;                                byte[] buf2 = new byte[recv.getLength()];                System.arraycopy(recv.getData(), 0, buf2, 0, recv.getLength());                if ((tmpCom = Command.createCommand(                        buf2, recv.getAddress().getHostAddress())) != null) {                    //                System.out.println("2"+recv.getAddress().getHostAddress());                    GlobalVar.COMMAND_QUEUE_EMPTY.acquire();                    //                System.out.println("3"+recv.getAddress().getHostAddress());                    GlobalVar.pushCommand(tmpCom);                    GlobalVar.COMMAND_QUEUE_fULL.release();                }            }        } catch (SocketException ex) {        } catch (IOException ex) {        } catch (InterruptedException ex) {        }            }}

⌨️ 快捷键说明

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