    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.io.IOException;
    006    import java.net.DatagramPacket;
    007    import java.net.InetAddress;
    008    import java.net.MulticastSocket;
    009    import java.net.SocketTimeoutException;
    010
    011    @SideOnly(Side.CLIENT)
    012    public class ThreadLanServerFind extends Thread
    013    {
    014        /** The LanServerList */
    015        private final LanServerList localServerList;
    016
    017        /** InetAddress for 224.0.2.60 */
    018        private final InetAddress broadcastAddress;
    019
    020        /** The socket we're using to receive packets on. */
    021        private final MulticastSocket socket;
    022
    023        public ThreadLanServerFind(LanServerList par1LanServerList) throws IOException
    024        {
    025            super("LanServerDetector");
    026            this.localServerList = par1LanServerList;
    027            this.setDaemon(true);
    028            this.socket = new MulticastSocket(4445);
    029            this.broadcastAddress = InetAddress.getByName("224.0.2.60");
    030            this.socket.setSoTimeout(5000);
    031            this.socket.joinGroup(this.broadcastAddress);
    032        }
    033
    034        public void run()
    035        {
    036            byte[] var2 = new byte[1024];
    037
    038            while (!this.isInterrupted())
    039            {
    040                DatagramPacket var1 = new DatagramPacket(var2, var2.length);
    041
    042                try
    043                {
    044                    this.socket.receive(var1);
    045                }
    046                catch (SocketTimeoutException var5)
    047                {
    048                    continue;
    049                }
    050                catch (IOException var6)
    051                {
    052                    var6.printStackTrace();
    053                    break;
    054                }
    055
    056                String var3 = new String(var1.getData(), var1.getOffset(), var1.getLength());
    057                System.out.println(var1.getAddress() + ": " + var3);
    058                this.localServerList.func_77551_a(var3, var1.getAddress());
    059            }
    060
    061            try
    062            {
    063                this.socket.leaveGroup(this.broadcastAddress);
    064            }
    065            catch (IOException var4)
    066            {
    067                ;
    068            }
    069
    070            this.socket.close();
    071        }
    072    }