示例#1
0
 public static void GetAnswers(object sender, AnswerEventArgs args)
 {
     if (acceptData == AcceptState.Ready)
     {
         if (args.data is DirectoryInfo)
         {
             Directory.CreateDirectory(((DirectoryInfo)args.data).FullName);
         }
         if (args.data is FileStream)
         {
             FileStream f   = (FileStream)args.data;
             FileStream tag = new FileStream(f.Name, FileMode.Create);
             f.CopyTo(tag);
         }
         else if (args.data.Equals("Done"))
         {
             acceptData = AcceptState.Done;
         }
         else
         {
             client.Send("Data");
         }
     }
     else if (acceptData == AcceptState.NotReady)
     {
         if (args.data is DirectoryInfo)
         {
             mainWindow.ShowShareFolder((DirectoryInfo)(args.data));
         }
     }
     else if (acceptData == AcceptState.Done)
     {
     }
 }
示例#2
0
        private static void AcceptAsyncResult(IAsyncResult ar)
        {
            try
            {
                // aceptamos la conexion
                var    instance_state = (AcceptState)ar.AsyncState;
                var    os_socket      = instance_state.os_socket;
                Socket usr_socket;
                try
                {
                    usr_socket = os_socket.EndAccept(ar);
                } catch (Exception e)
                {
                    STrace.Exception(typeof(Listener).FullName, e, "TCP.Listener.AcceptAsyncResult=>EndAccept");
                    return;
                } finally
                {
                    if (instance_state.usr_acceptor != null)
                    {
                        var new_instance_state = new AcceptState
                        {
                            os_socket    = os_socket,
                            usr_acceptor = (Acceptor)instance_state.usr_acceptor.Clone()
                        };
                        os_socket.BeginAccept(AcceptAsyncResult, new_instance_state);
                    }
                    else
                    {
                        STrace.Exception(typeof(Listener).FullName, new ApplicationException("El TCP.Listener perdio la referencia al aceptor EP:" + os_socket.LocalEndPoint));
                    }
                }

                Debug.Assert(instance_state.usr_acceptor != null);
                var instance_acceptor = (Acceptor)instance_state.usr_acceptor.Clone();
                instance_acceptor.os_socket = usr_socket;
                try
                {
                    instance_acceptor.OnConnection();
                    instance_acceptor.StartReceiver();
                    return;
                }
                catch (ObjectDisposedException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    STrace.Exception(typeof(Listener).FullName, e, "TCP.Listener.AcceptAsyncResult=>acceptor.OnConnection");
                    instance_acceptor.OnceOnInternalError();
                }
            }
            catch (ObjectDisposedException)
            {
                return;
            }
            catch (Exception e)
            {
                STrace.Exception(typeof(Listener).FullName, e, "Listener.OnConnection");
            }
        }
示例#3
0
        private void AcceptCallBack(IAsyncResult result)
        {
            AcceptState state = result.AsyncState as AcceptState;

            if (m_socket != state.WorkSocket)
            {
                return;
            }
            try
            {
                var socket = state.WorkSocket.EndAccept(result);
                if (null == socket)
                {
                    throw new Exception("accept failure.");
                }

                Connections.Add(new ClientConnection(socket, OnConnectionClose));
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log("accept failure :" + e.Message);
                State = EConnectionState.ACCEPTING_ERROR;
                Disconnect();
            }
        }
示例#4
0
 private void RefreshECH()
 {
     //The refresh functions are mainly used for scalable UI and data handling. The majority of them are quite simple, but make changes to the underlying logic behind ECH's simple.
     //The below refreshes the list box of ECH's.
     lstbxECH.Items.Clear();
     foreach (EventConvoHandler ECH in ECHList)
     {
         string tempstring = ECH.ButtonText + "-";
         foreach (int AcceptState in ECH.Acceptance_States)
         {
             tempstring += AcceptState.ToString();
         }
         lstbxECH.Items.Add(tempstring);
     }
 }
示例#5
0
        public Listener(String shortdesc, IPEndPoint listen_address, Acceptor acceptor)
        {
            traceTip      = shortdesc;
            usr_acceptor  = acceptor;
            ListenAddress = listen_address;
            os_socket     = new Socket(AddressFamily.InterNetwork,
                                       SocketType.Stream, ProtocolType.Tcp);
            pendings = 100;
            os_socket.Bind(ListenAddress);
            os_socket.Listen((pendings == 0 ? 1 : pendings));
            var instance_state = new AcceptState
            {
                os_socket    = os_socket,
                usr_acceptor = usr_acceptor
            };

            os_socket.BeginAccept(AcceptAsyncResult, instance_state);
        }
示例#6
0
        public Listener(String shortdesc, IPEndPoint listenAddress, Acceptor acceptor)
        {
            _traceTip     = shortdesc;
            UsrAcceptor   = acceptor;
            ListenAddress = listenAddress;
            _osSocket     = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _osSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);
            _pendings = 100;
            _osSocket.Bind(ListenAddress);
            _osSocket.Listen((_pendings == 0 ? 1 : _pendings));
            var instanceState = new AcceptState
            {
                OsSocket     = _osSocket,
                usr_acceptor = UsrAcceptor
            };

            _osSocket.BeginAccept(AcceptAsyncResult, instanceState);
        }
示例#7
0
        public void Start()
        {
            try
            {
                ListenSocket.Bind(IPPoint);
                ListenSocket.Listen(10);
                Console.WriteLine("Started.");
                while (true)
                {
                    AcceptState.Reset();
                    Console.WriteLine("Waiting for a connection...");
                    ListenSocket.BeginAccept(new AsyncCallback(AcceptCallback), ListenSocket);
                    AcceptState.WaitOne();
                }
            }
            catch (Exception e)
            {
#if DEBUG
                Console.WriteLine(e.Message);
#endif
            }
        }
示例#8
0
        private void AcceptCallback(IAsyncResult asyncResult)
        {
            AcceptState.Set();
            Socket listener = (Socket)asyncResult.AsyncState;
            Socket handler  = listener.EndAccept(asyncResult);
            string login    = string.Empty;

            try
            {
                login = Auth(handler);
            }
            catch (Exception)
            {
                handler.Send(new Data()
                {
                    Name = "Server", Message = "Go away!", Target = string.Empty
                }.ToBytes());
                handler.Shutdown(SocketShutdown.Both);
                handler.Close();
                return;
            }
            LoopReceiver(login);
        }