Ejemplo n.º 1
0
        private void _server_OnAccepted(object userToken)
        {
            //IUserToken ut = (IUserToken)userToken;
            //log4j.Info(ut.ID);
            UserToken ut = (UserToken)userToken;

            try
            {
                ut.Index = sessionIDToNumber.Add(ut.ID, out bool isAdded);
                OnAccepted?.Invoke(userToken);
            }
            catch (OverflowException ex)
            {
                log4j.Info(ex.Message + ", sessionID: " + ut.ID);
                // ((SAEA.Sockets.Core.Tcp.IocpServerSocket)_server).Disconnect((IUserToken)userToken, ex);
                // (_server as SAEA.Sockets.Core.Tcp.IocpServerSocket).Disconnect(userToken as IUserToken, ex);

                // delay some time to disconnect client, cause client is still in connecting state. otherwise client not having correct connection state.
                Task.Delay(500).
                ContinueWith(t =>
                {
                    (_server as SAEA.Sockets.Core.Tcp.IocpServerSocket).Disconnect(userToken as IUserToken, ex);
                });
            }
        }
Ejemplo n.º 2
0
 void Awake()
 {
     currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory());
     items            = new List <Transform>();
     acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(resultPath));
     cancelButton.onClick.AddListener(() => OnCancelled?.Invoke());
 }
Ejemplo n.º 3
0
        internal override void InvokeEvent(ServerType type, IConnection conn, IMessage msg)
        {
            switch (type)
            {
            case ServerType.Started:
                OnStarted?.Invoke(conn, msg);
                break;

            case ServerType.Accepted:
                OnAccepted?.Invoke(conn, msg);
                break;

            case ServerType.Sended:
                OnSended?.Invoke(conn, msg);
                break;

            case ServerType.Received:
                OnRecieved?.Invoke(conn, msg);
                break;

            case ServerType.Disconnected:
                OnDisconnected?.Invoke(conn, msg);
                break;

            case ServerType.Stopped:
                OnStopped?.Invoke(conn, msg);
                break;
            }
        }
Ejemplo n.º 4
0
        private void Accept_Completed(object sender, SocketAsyncEventArgs e)
        {
            try
            {
                Socket clientSocket = e.AcceptSocket;

                if (clientSocket != null)
                {
                    SocketAsyncEventArgs args = new SocketAsyncEventArgs();
                    byte[] szData             = new byte[1024];
                    args.SetBuffer(szData, 0, 1024);    //수신 버퍼 할당
                    args.UserToken  = clientSocket;
                    args.Completed += new EventHandler <SocketAsyncEventArgs>(Receive_Completed);

                    var info = new ClientInfo(clientSocket);
                    if (_ClientList.ContainsKey(info.IP))
                    {
                        throw new Exception("asdf");
                    }

                    _ClientList.Add(info.IP, info);

                    clientSocket.ReceiveAsync(args);
                    OnAccepted?.Invoke(this, EventArgs.Empty);
                }

                e.AcceptSocket = null;
                clientSocket.AcceptAsync(e); //요청 소켓 처리 후 수락 대기 상태 변경
            }
            catch (Exception ex)
            {
                WriteLog.WriteLogger(ex.ToString());
            }
        }
    public override void Awake()
    {
        base.Awake();

        acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(this));
        rejectButton.onClick.AddListener(() => OnRejected?.Invoke(this));
        cancelButton.onClick.AddListener(() => OnCancelled?.Invoke(this));
    }
Ejemplo n.º 6
0
        /// <summary>
        ///     Will fire all events according to the queued messages
        /// </summary>
        public void Work()
        {
            if (Stopped)
            {
                throw new InvalidOperationException($"{nameof(EasySocket)} was stopped");
            }
            SocketAsyncEventArgs result;

            while (!_acceptedSockets.IsEmpty)
            {
                if (_acceptedSockets.TryDequeue(out result))
                {
                    OnAccepted?.Invoke(Socket, result);
                }
            }

            while (!_receivedData.IsEmpty)
            {
                if (_receivedData.TryDequeue(out result))
                {
                    OnReceived?.Invoke(Socket, result);
                }
            }

            while (!_receivedFromData.IsEmpty)
            {
                if (_receivedFromData.TryDequeue(out result))
                {
                    OnReceivedFrom?.Invoke(Socket, result);
                }
            }

            while (!_receivedMessageFromData.IsEmpty)
            {
                if (_receivedMessageFromData.TryDequeue(out result))
                {
                    OnReceivedMessageFrom?.Invoke(Socket, result);
                }
            }

            while (!_sendComplete.IsEmpty)
            {
                if (_sendComplete.TryDequeue(out result))
                {
                    OnSent?.Invoke(Socket, result);
                }
            }

            while (!_sendToComplete.IsEmpty)
            {
                if (_sendToComplete.TryDequeue(out result))
                {
                    OnSentTo?.Invoke(Socket, result);
                }
            }
        }
Ejemplo n.º 7
0
    void Start()
    {
        inputField.caretPosition = 0; // desired cursor position

        inputField.GetType().GetField("m_AllowInput", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(inputField, true);
        inputField.GetType().InvokeMember("SetCaretVisible", BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, null, inputField, null);

        acceptButton.onClick.AddListener(() => OnAccepted?.Invoke(inputField.text));
        cancelButton.onClick.AddListener(() => OnCancelled?.Invoke());
    }
Ejemplo n.º 8
0
        private void AcceptedCallback(IAsyncResult ar)
        {
            try
            {
                Socket s = listener.EndAccept(ar);
                OnAccepted?.Invoke(new SocketClient(s));
            } catch { }

            if (Running)
            {
                listener.BeginAccept(AcceptedCallback, null);
            }
        }
        private IEnumerator Accepting()
        {
            while (true)
            {
                IAsyncResult result = m_Socket.BeginAccept(null, null);
                while (!result.IsCompleted)
                {
                    yield return(null);
                }

                Socket newClient = m_Socket.EndAccept(result);
                OnAccepted?.Invoke(newClient);
            }
        }
Ejemplo n.º 10
0
 protected virtual void RaiseOnAccepted(int num, IUserToken userToken)
 {
     OnAccepted?.BeginInvoke(num, userToken, null, null);
 }
Ejemplo n.º 11
0
 void HandleAccepted(object sender, EventArgs e)
 {
     OnAccepted?.Execute(ViewModel);
 }
Ejemplo n.º 12
0
 private void UdpServer_OnAccepted(object obj)
 {
     Console.ForegroundColor = ConsoleColor.Red;
     Console.WriteLine($"UdpServer_OnAccepted:{((IUserToken)obj).ID}");
     OnAccepted?.Invoke(((IUserToken)obj).ID);
 }
Ejemplo n.º 13
0
 private void _server_OnAccepted(object obj)
 {
     OnAccepted?.Invoke(obj);
 }
Ejemplo n.º 14
0
 void HandleAccepted(object sender, EventArgs e)
 {
     OnAccepted?.Invoke();
 }
Ejemplo n.º 15
0
 protected override void OnFailed()
 {
     OnAccepted?.Invoke(new TcpSocketAccept(Status, Socket, Connection, null));
 }
Ejemplo n.º 16
0
 protected override void OnCompleted()
 {
     OnAccepted?.Invoke(new TcpSocketAccept(Status, Socket, Connection, GetEndpoint));
 }
Ejemplo n.º 17
0
 private void OnAcceptedComplete(object sender, SocketAsyncEventArgs socketAsyncEventArgs)
 {
     Task.Run(() => OnAccepted?.Invoke(this, socketAsyncEventArgs));
     SetupAccept();
 }