Search
Website

Silverlight Recipes : Using Sockets to Communicate over TCP (part 5) - The Policy Server

Published 1 min readBy Programming4us Editorial Team

4.4. The Policy Server

The policy server is similarly implemented as a console program that listens on all available IP addresses, bound to a well-known port 943. Listing 7 shows the code for the policy server.

Listing 7. Implementation for the PolicyServer type in PolicyListener.cs

After a connection request is accepted by the policy server, it attempts to receive a policy request from the client and checks it for validity by comparing it to the string literal <policy-file-request/>. If valid, the policy file is read into memory and sent back to the client through the connected client socket. When the send is completed, the socket connection is closed, and the policy server keeps listening for more policy requests.