Exemplo n.º 1
0
        private void DetectReconnection(Socket Sck)
        {
            int ReconnectVal = 0;

            int[] SocketIDS = new int[500];
            foreach (KeyValuePair <int, Client> item in FuzzyServer.SocketList)
            {
                if (item.Value.CLOSEDSTATE == Client.ClosedStates.FORCIBLY)
                {
                    if (item.Value.SOCKET.AddressFamily == Sck.AddressFamily)
                    {
                        Message.Write("Reconnected!", ConsoleMessage.MessageType.CONNECT);
                        ReconnectVal++;
                        SocketIDS[ReconnectVal] = item.Key;
                    }
                }
            }

            if (ReconnectVal > 1)
            {
                for (int i = 1; i < SocketIDS.Length; i++)
                {
                    FuzzyServer.SocketList.Remove(SocketIDS[i]);
                }
            }
            else if (ReconnectVal == 1)
            {
                FuzzyServer.SocketList.Remove(SocketIDS[1]);
            }
        }
Exemplo n.º 2
0
 // Receive
 private void ReceiveData(IAsyncResult State)
 {
     try
     {
         if (!ReceiveData_Permission)
         {
             throw new Exception("Receive Data Permission Is False");
         }
         CurrentSocket = (Socket)State.AsyncState;
         int ReceivedInt = CurrentSocket.EndReceive(State);
         copyBuff = new byte[ReceivedInt];
         Array.Copy(_buff, copyBuff, ReceivedInt);
         String Data = Encoding.UTF8.GetString(copyBuff);
         _buff = new byte[1024];
         if (!string.IsNullOrEmpty(Data))
         {
             DataParser parser = new DataParser(Data, CurrentSocket, m_initializeType);
             parser.Parse();
             Thread reciveTask = new Thread(new ThreadStart(() => { ReceiverTask(Data, GetClientBySocket(CurrentSocket)); }));
             if (ReceiverTask != null)
             {
                 reciveTask.Start();
             }
             CurrentSocket.BeginReceive(_buff, 0, _buff.Length, SocketFlags.None, new AsyncCallback(ReceiveData), CurrentSocket);
         }
         else
         {
             Message.Write(CurrentSocket.RemoteEndPoint.ToString(), ConsoleMessage.MessageType.DISCONNECT);
         }
     }
     catch (Exception Ex)
     {
         ConsoleMessage.WriteException(Ex.Message, "Listener.cs", "ReceiveData");
         SocketList[FoundSocketID(CurrentSocket)].CLOSEDSTATE = Client.ClosedStates.FORCIBLY;
     }
 }
Exemplo n.º 3
0
 //
 //STARTER METHOD
 //
 public void startListen()
 {
     try
     {
         //
         //PERMISSION TRUE/FALSE CONTROL
         //
         if (!AcceptClient_Permission)
         {
             throw new Exception("Accept Client Permission Is False");
         }
         ServerSocket.Bind(localEP);
         ServerSocket.Listen(2);
         SocketStatePrivate = true;
         ServerSocket.BeginAccept(new AsyncCallback(AcceptSocket), ServerSocket);
     }
     catch (Exception Ex)
     {
         Message.Write(Ex.Message.ToString(), ConsoleMessage.MessageType.ERROR);
     }
 }