示例#1
0
 protected void OnConversationRemoved(TcpConversation conversation)
 {
     if (ConversationRemoved != null)
     {
         ConversationRemoved(this, conversation);
     }
 }
示例#2
0
 internal void RemoveConversation(TcpConversation conversation)
 {
     _Conversations.Remove(conversation);
     OnConversationRemoved(conversation);
 }
示例#3
0
        /*
         * private static int listcon=0;
         * protected void mScannerTimeout_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
         * {
         *
         * //    if(_roomlist>conversation._RoomView.RoomList.Count)
         *      // _ConnectTime.Enabled = false;
         *   lock (this)
         *   {
         *       TaskTimer tt = (TaskTimer)sender;
         *
         *
         *       Room rom = tt.TCPCON._RoomView.RoomList.Values[listcon];
         *       string str = tt.TCPCON.GetRoomStatusString(rom);
         *       SendMessageToAllClient(str);
         *
         *
         *       if (tt.TCPCON._RoomView.RoomList.Count <= listcon+1)
         *       {
         *           tasktime.Enabled = false;
         *           listcon = 0;
         *           return;
         *       }
         *
         *       listcon = listcon + 1;
         *       return;
         *   }
         *
         * }
         * */
        public void StartListen()
        {
            try
            {
                _CurrentSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                _CurrentSocket.Bind(_ServerIPEndPoint);
            }
            catch (SocketException)
            {
                StopListen();
            }

            while (true)
            {
                try
                {
                    _CurrentSocket.Listen(200);
                    _CurrentSocket.Blocking = true;

                    //Thread thread = new Thread(new ThreadStart(AcceptConnection));
                    //thread.Start();
                    Socket newSocket = _CurrentSocket.Accept();

                    // _roomlist = 0;
                    // Create a conversation
                    TcpConversation conversation = new TcpConversation(newSocket, this);



                    // Save the conversation
                    _Conversations.Add(conversation);
                    OnConversationAdded(conversation);

                    /*
                     * for (int ii = 0; ii < conversation._RoomView.RoomList.Count; ii++)
                     * {
                     *  Room rom = conversation._RoomView.RoomList.Values[ii];
                     *  string str = conversation.GetRoomStatusString(rom);
                     *  SendMessageToAllClient(str);
                     * }
                     */
                    Room   rom = conversation._RoomView.RoomList.Values[0];
                    string str = conversation.GetRoomStatusString(rom);
                    SendMessageToAllClient(str);
                    //  _ConnectTime.Enabled = true;
                    //   _ConnectTime.Elapsed += new System.Timers.ElapsedEventHandler(mScannerTimeout_Elapsed);

                    // tasktime.Elapsed +=new System.Timers.ElapsedEventHandler(mScannerTimeout_Elapsed);
                    //tasktime.Interval = 3000;
                    // tasktime.TCPCON = conversation;
                    // tasktime.Enabled = true;

                    //  tasktime.ID = 0;

                    //     listcon = 0;
                }
                catch (Exception ee)
                {
                    aLog.WriteLog(ee.Message.ToString() + ee.Source.ToString());
                    Console.WriteLine(ee.Message.ToString() + ee.Source.ToString());
                    //MessageBox.Show(ee.Message);
                }
            }
        }