Hi!
I've implemented a solution that uses asynchronous sockets to push information from a server to all connected Silverlight clients.
I'm having a few problems with the Push Server and need some clarification since this is the first time I'm working with Sockets and in an fully asynchronous environment.
Right now the Push Server accepts new socket connections and adds them to a Generic List. The Generic List is of a custom Type that I've implemented (named AsyncClientConnection) used to manage a single asynchronous socket connection.
The Push Server has a Timer and when a specified amount of time has passed it opens a file and sends the contents to all connected sockets (in the Generic List). It's simulating what is going to happen in the future, when the server will be receiving raw byte data from a physical device. While the server is sending the data to the client it cleans up any disconnected/disposed clients.
My problem is with the Generic List, it's not thread safe and isn't working well in this asynchronous scenario. When a new socket connects to the server, a new AsyncClientConnection is created for it and is added to the generic list; but if the server is in the middle of pushing the file to the connected clients it's using the generic list so when the new AsyncClientConnection is added to the list, the list is modified,and an exception occurs for obvious reasons.
I've never seriously used threads before (I've only just tried them out to make sure that I understood the theory of them), and have never used asynchronous sockets before, so I'm a little lost when it comes to the tools out there that I can use to fix the problem.
I'm even questioning if there's a different way to maintain the AsyncClientConnection types all together.
Any suggestions would be great!
Thanks a lot,
-Frinny