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