Exemple #1
0
        static public IPCSocketServerThread GetNewServer(string localAddress, int localPort)
        {
            TcpConnection ServerConnection = new TcpConnection();

            if (ServerConnection.Listen(localAddress, localPort))
            {
                IPCSocketServerThread Result = new IPCSocketServerThread(ServerConnection);
                Result.Start();
                return(Result);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        protected override void Execute()
        {
            _Connection = new TcpConnection();
            if (_Connection.Listen(_Address, _Port))
            {
                RaiseBoundEvent();

                while (!_Stop)
                {
                    // Accept a new connection
                    if (_Connection.CanAccept(500)) // 1/2 of a second
                    {
                        TcpConnection NewConnection = _Connection.AcceptTCP();
                        if (NewConnection != null)
                        {
                            // Wait up to 5 seconds for the request string
                            string Request = NewConnection.ReadLn("\0", 5000);
                            if (Request.ToLower().Replace(" ", "") == "<policy-file-request/>")
                            {
                                ConnectionAcceptedEventArgs.Raise(this, ConnectionAcceptedEvent, _Address, _Port, NewConnection.GetRemoteIP(), NewConnection.GetRemotePort());
                                RaiseMessageEvent("Answered policy file request from " + NewConnection.GetRemoteIP() + ":" + NewConnection.GetRemotePort().ToString());

                                NewConnection.WriteLn("<?xml version=\"1.0\"?>");
                                NewConnection.WriteLn("<cross-domain-policy>");
                                NewConnection.WriteLn("   <allow-access-from domain=\"*\" to-ports=\"" + _AllowedPorts + "\"/>");
                                NewConnection.WriteLn("   <site-control permitted-cross-domain-policies=\"all\"/>"); // TODO Maybe add property to determine whether this should be all or master-only
                                NewConnection.WriteLn("</cross-domain-policy>");
                                NewConnection.Write("\0");
                            }
                            else
                            {
                                RaiseErrorMessageEvent("Invalid policy file request from " + NewConnection.GetRemoteIP() + ":" + NewConnection.GetRemotePort().ToString());
                            }
                            NewConnection.Close();
                        }
                    }
                }
                _Connection.Close();
            }
            else
            {
                RaiseErrorMessageEvent("Flash Socket Policy Thread: Unable to listen on " + _Address + ":" + _Port);
                RaiseBindFailedEvent();
            }
        }