开发者

Problem with sending messages from a silverlight client using websockes prototype

开发者 https://www.devze.com 2023-02-28 18:00 出处:网络
I need to use websockets for implementing a bi-directional communication bet开发者_如何转开发ween my silverlight client and the server. I could connect/disconnect to/from the server and both OnOpen &

I need to use websockets for implementing a bi-directional communication bet开发者_如何转开发ween my silverlight client and the server. I could connect/disconnect to/from the server and both OnOpen & OnClose events in both of client and server fired well, but i have a problem with sending messages to the server :

when I send a message to the server, I don't get any error at the client side where as the OnMessage operation of my service at the server never called(the message sent from client without any problem but server never receive that!).

You can get my sample code here.

Thanks


Policy file exist only on server side.

Please take a look on : MSDN

You can deliver policy file on HTTP or by a policy server (on port 943).

To use HTTP to retrieve the socket policy file, an application should set the SocketAsyncEventArgs::SocketClientAccessPolicyProtocol property to Http on the System.Net.Sockets::SocketAsyncEventArgs instance passed to the Socket::ConnectAsync method.

Good luck


"One additional restriction on using the sockets classes is that the destination port range that a network application is allowed to connect to must be within the range of 4502-4534. These are the only destination ports allowed by a connection from a Silverlight application using sockets."

Source:
http://msdn.microsoft.com/en-us/library/cc645032%28v=VS.95%29.aspx

Having a policy file will only make it work with the mentioned port range. Without a policy file it will not work at all. These two (and many more) restrictions do not apply to trusted applications.

http://social.msdn.microsoft.com/Forums/en/silverlightdeveloper/thread/b4f7120d-71d9-4132-9c31-b456803cd32f


Update

try to change your policy file to this:

<access-policy>
<cross-domain-access>
<policy>
  <allow-from http-request-headers="*">
    <domain uri="*" />
  </allow-from>
  <grant-to>
    <socket-resource port="4502-4534" protocol="tcp" />
  </grant-to>
</policy>
</cross-domain-access>
</access-policy>
0

精彩评论

暂无评论...
验证码 换一张
取 消