예제 #1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (tracker != null)
     {
         tracker.Close();
         tracker = null;
         button2.Enabled = true;
     }
 }
예제 #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (tracker == null)
            {
                tracker = new Tracker();
                button2.Enabled = false;
                IPText.Text = tracker.IP;

                MaxPeerNumber.Value = tracker.max_peer;
                MaxRoomNumber.Value = tracker.max_room;
                LogCheck.Checked = tracker.log;
                tracker.LogText = LogText;
            }
        }
예제 #3
0
            /// <summary>
            /// Constructor of Client Handler
            /// </summary>
            /// <param name="tc">Tracker</param>
            /// <param name="handler">Socket handler</param>
            public ClientHandler(Tracker tc, Socket handler)
            {
                this.handler = handler;
                Tracker = tc;

                // Get IP and Peer ID | Peer ID must be 4 length byte
                IP = (handler.RemoteEndPoint as IPEndPoint).Address.ToString();
                PeerID = (handler.RemoteEndPoint as IPEndPoint).Address.ToString();
                string[] split_res = PeerID.Split('.');
                if (split_res[split_res.Length - 1].Length < 3)
                {
                    PeerID = "P";
                    for (int i = 0; i < 3 - split_res[split_res.Length - 1].Length; i++) PeerID += "0";
                    PeerID += split_res[split_res.Length - 1];
                }
                else
                {
                    PeerID = "P" + split_res[split_res.Length - 1];
                }

                // Thread for Receving Message from Peer
                MsgThread = new Thread(RecvrMsgCallback);
                MsgThread.Start();

                // Thread for timeout
                Thread CounterThread = new Thread(Counter);
                CounterThread.Start();

                // Add PeerID to Dictionary of IP
                Tracker.IPPeers.Add(PeerID, IP);
            }