Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 837637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:10:24+00:00 2026-05-15T05:10:24+00:00

I basically try to reproduce the Socket example from here: http://www.silverlightshow.net/items/Sockets-and-their-implementation-in-SL2-Beta-1-including-a-chat-like-example.aspx I only made

  • 0

I basically try to reproduce the Socket example from here: http://www.silverlightshow.net/items/Sockets-and-their-implementation-in-SL2-Beta-1-including-a-chat-like-example.aspx
I only made a small change in the client side, i.e.,

 String safeHost = "127.0.0.1";
            int port = 4509;

Then I got this permission error? Any idea why?

Unhandled Error in Silverlight Application An attempt was made to access a socket in a way forbidden by its access permissions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T05:10:24+00:00Added an answer on May 15, 2026 at 5:10 am

    I believe that the way the socket security checks work you need to use the same url string that your application uses. to make sure i am using the correct string i have always used this to construct my DNSEndPoint:

    int Port = 4509;
    DnsEndPoint ep = new DnsEndPoint(Application.Current.Host.Source.DnsSafeHost, Port, AddressFamily.InterNetwork);
    Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    sock.NoDelay = true;
    SocketAsyncEventArgs ea = new SocketAsyncEventArgs{RemoteEndPoint  = ep};
    //set up completed event handler et al.
    sock.ConnectAsync(ea);
    

    I have used this exact code in a similar chat application. By using the Application.Current.Host.Source.DnsSafeHost Property you ensure that you are using the same Dns Name to access the server with the socket that the browser is using for HttpRequests.

    Also are you serving the access policy file on port 943, this is another requirement of the socket support in Silverlight.

    EDIT

    To Confirm that you are serving the policy file you can do a number of things.

    1. install Fiddler, you can use it to debug all http traffic hitting your server, you should be able to see the request for the policy file.
    2. serve your policy file dynamically and then set a break point in your server application to confirm that it is being served. this is what i did.

    here is the code i used to serve the policy file:

    public abstract class Server
    {
        protected Socket Listener { get; set; }
        protected int Port { get; private set; }
        protected int Backlog { get; private set; }
        protected bool isStopped { get; set; }
        protected SocketAsyncEventArgs AcceptArgs {get;set;}
    
        public Server(int port)
        {
            AcceptArgs = new SocketAsyncEventArgs();
            AcceptArgs.Completed += new EventHandler<SocketAsyncEventArgs>(Accept_Completed);
            isStopped = true;
            Port = port;
            Backlog = 100;
        }
    
    
        public Server(int port, int backlog)
        {
            isStopped = true;
            Port = port;
            Backlog = backlog;
        }
    
        public void Start()
        {
            isStopped = false;
    
            Listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ep = new IPEndPoint(IPAddress.Any, Port);
            Listener.ExclusiveAddressUse = true;
            Listener.Bind(ep);
            //Console.WriteLine("Listening on " + Port);
            Listener.Listen(Backlog);
    
            Listener.AcceptAsync(AcceptArgs);
        }
    
        void Accept_Completed(object sender, SocketAsyncEventArgs e)
        {
            if (isStopped) return;
            Socket client = e.AcceptSocket;
            //Console.WriteLine("Accepted Connection From: " + client.RemoteEndPoint.ToString());
            e.AcceptSocket = null;
            Listener.AcceptAsync(AcceptArgs);
            HandleClient(client);
        }
    
        public virtual void Stop()
        {
            if (isStopped) throw new InvalidOperationException("Server already Stopped!");
            isStopped = true;
            try
            {
                Listener.Shutdown(SocketShutdown.Both);
                Listener.Close();
            }
            catch (Exception)
            {
            }
        }
    
        protected abstract void HandleClient(Socket Client);
    }
    public class PolicyServer : Server
    {
        public const String policyStr = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                                            <access-policy>
                                                <cross-domain-access>
                                                    <policy>
                                                        <allow-from>
                                                            <domain uri=""*"" />
                                                        </allow-from>
                                                        <grant-to>
                                                            <socket-resource port=""4530"" protocol=""tcp"" />
                                                        </grant-to>
                                                    </policy>
                                                </cross-domain-access>
                                            </access-policy>";
        private byte[] policy = Encoding.ASCII.GetBytes(policyStr);
        private static string policyRequestString = "<policy-file-request/>";
    
        public PolicyServer(): base(943)
        {
        }
    
        protected override void HandleClient(Socket socket)
        {
            TcpClient client = new TcpClient { Client = socket };
            Stream s = client.GetStream();
            byte[] buffer = new byte[policyRequestString.Length];
            client.ReceiveTimeout = 5000;
            s.Read(buffer, 0, buffer.Length);//read in the request string, but don't do anything with it
                                                         //you could confirm that it is equal to the policyRequestString
            s.Write(policy, 0, policy.Length);
            s.Flush();
    
            socket.Shutdown(SocketShutdown.Both);
            socket.Close(1);
            client.Close();
        }
    }
    

    Then to use it:

    PolicyServer ps = new PolicyServer();
    ps.Start();
    //then when shutting down
    ps.Stop();
    

    I hosted this “server” in the same process that was running the rest of the Chat Server component. Set a breakpoint in HandleClient to confirm if it is receiving the request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to reproduce a threading error condition within an HTTP Handler. Basically,
The WSDL file is located here : http://www.rasd.ro/BSEFinancialsWS/financials.asmx?WSDL Here's the operation page: http://www.rasd.ro/BSEFinancialsWS/financials.asmx?op=GetCompanyBalance For
I'll try and be as precise as possible here! Basically, I have an app
I'll try to simplify and make clear my other question here. I am basically
I' still newby to this so I'll try to explain what I'm doing. Basically
Basically I have three pages. -A page with all possible search results for example:
Basically I want to go from -1 to 1 in n steps, including -1
I am moving some svn repositories to Git. So, what I basically try to
I would like to load variables from a text file. For example, my text
I try to write a wrapper class for leveldb. Basically the part of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.