37789

Why does my Silverlight Socket Policy File not work?

Question:

I've got a silverlight client, using SL4, and a C# server using .NET 4. The server opens a port on 4525, to which the client is intended to connect. Now, if I can ask that you simply read the following, we can probably avoid me having to post any further code:

The client attempts to make the connection to the server, opens up the connection for the policy file, requests the policy file, and gets returned the policy file. What is not happening, is the onConnect event in the client. Before I implemented a policy server, the client would connect on 4525, and execute the onConnect event, but immediately fail because there was no policy server. Now that I have implemented the policy server, it appears that it never detects the finalization of its delivery.

Here is the transmission summary:

Client: <policy-file-request/> Server: <?xml version="1.0" encoding ="utf-8"?> <access-policy> <cross-domain-access> <policy> <allow-from> <domain uri="*:4525" /> </allow-from> <grant-to> <socket-resource port="4525" protocol="tcp" /> </grant-to> </policy> </cross-domain-access> </access-policy>

Effectively; the only question I am trying to answer is this: Am I missing something from my policy file, or do I need to conclude its submission to the client in any particular manner, in order for my client to detect its delivery?

Things of note: The Client successfully establishes its connection to the policy server The policy server successfully writes the policy back to the client The 'real' servers port is successfully opened The client 'can' connect to the 'real' server

Thank you all for your time, I am sure someone will be able to help.

<strong>Code Request</strong> <em>Client Connection</em>

Not sure that it's of any further consequence toward finding an answer; but:

private static DnsEndPoint IP_END_POINT = new DnsEndPoint("192.168.0.36", 4525, AddressFamily.InterNetwork); public MainPage() { try { InitializeComponent(); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs connectEventArgs = new SocketAsyncEventArgs(); connectEventArgs.RemoteEndPoint = IP_END_POINT; connectEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ConnectionEstablished); socket.ConnectAsync(connectEventArgs); } catch (Exception e) { } }

<strong>New Development</strong> <em>'Connection Established' fires!</em>

So it turns out that if I want a minute or so, my 'ConnectionEstablished' event does eventually fire. What I get from it, however, is not so encouraging.

I ended up with a SocketError of 'AccessDenied', and a message of 'An attempt was made to access a socket in a way forbidden by its access permissions.', and as can be expected, my server never accepts the connection. I know that the server has the port open, and can accept a connection, so this is quite the perplexing scenario.

Thanks again for anyone's help.

Answer1:

Try:

private static DnsEndPoint IP_END_POINT = new DnsEndPoint("192.168.0.36", 4525, AddressFamily.InterNetwork); public MainPage() { try { InitializeComponent(); socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); SocketAsyncEventArgs connectEventArgs = new SocketAsyncEventArgs(); connectEventArgs.RemoteEndPoint = IP_END_POINT; connectEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(ConnectionEstablished); if(!socket.ConnectAsync(connectEventArgs)) { ConnectionEstablished(/*Insert Args*/); //Handle real time execution } } catch (Exception e) { //write error somewhere } }

The <a href="http://msdn.microsoft.com/en-us/library/bb538102%28v=vs.95%29.aspx" rel="nofollow">documentation</a> indicates if ConnectAsync returns false then "The SocketAsyncEventArgs.Completed event on the System.Net.Sockets.SocketAsyncEventArgs object passed in the e parameter will not be raised."

Also, make sure you are logging the exception somewhere. There might be an exception which you are just breezing past.

<strong>Update</strong>:

<ul><li>Did you check the <a href="http://msdn.microsoft.com/en-us/library/cc645032%28v=vs.95%29.aspx" rel="nofollow">ClientAccessPolicy.xml</a> file? You would need to replace all the “ and ” characters with ".</li> <li>Have you tried adding connectEventArgs.UserToken = socket; before the ConnectAsync(connectEventArgs) call?</li> <li>Is the server receiving the request and sending a reply (may require the use of <a href="http://www.wireshark.org/download.html" rel="nofollow">Wireshark</a> on the client)?</li> <li>While debugging does connectEventArgs.Completed point to the correct method?</li> <li>While debugging, what happens if you "Step Over" (F10) until the method returns? Are other methods called?</li> <li>While debugging, if you "Step Over" (F10) socket.ConnectAsync(connectEventArgs) (but are still in the method) are there other threads in the Debug>Windows>Threads window? What happens if you switch to the other thread (right click on thread and select "Switch To Thread" or double click the thread)?</li> </ul>

Let me know how things turn out.

Recommend

  • HTML5: shared web worker with multiple connections
  • using restrict qualifier with C99 variable length arrays (VLAs)
  • Does JavaScript run out of timeout IDs?
  • JavaScript 'this' in different context
  • Why does SelectList SelectedValue work on HttpGet but not on HttpPost?
  • The schema returned by query is differ from base query
  • Sending JSON Object from Javascript to Silverlight then triggering an event to update Silverlight
  • How to override the attr_protected?
  • Swipable Linear/Relative Layout
  • Evaluating FeatherJS Authentication Needs
  • How can the java 'class' literal return different instances of the Class object for the sa
  • why adding a space after `(.+?)` can completely change the result
  • Can TextIO write to prefixes derived from the window maxTimestamp?
  • Newtonsoft inline formatting for subelement while serializing
  • Why is RAM in powers of 2?
  • Visual basic auto imports namespaces
  • YAJSW window service did not start
  • Add delivery info to query in SAP Crystal Reports
  • Replicating and differentiating portions of a form
  • proxy request in node.js / express
  • WPF Listbox commands
  • MAVEN : Run Multiple Maven Project using Maven Test
  • Converter from SAT to 3-SAT
  • How to implement Deep Linking in Roku SG application?
  • Invalid object name 'dbo.Item'
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • TextToSpeech.setEngineByPackageName() triggers NullPointerException
  • Breeze - Deleted Items nav properties bug
  • javaw.exe and eclipse startup problems
  • Apache 2.4 and php-fpm does not trigger apache http basic auth for php pages
  • Jquery - Jquery Wysiwyg return html as a string
  • Arrays break string types in Julia
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • WPF Applying a trigger on binding failure
  • Why joiner is not used after Sequence generator or Update statergy
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • need help with bizarre java.net.HttpURLConnection behavior
  • File not found error Google Drive API
  • Is it possible to post an object from jquery to bottle.py?