views:

101

answers:

3

I am writing a client/server application that will publish and subscribe to topics. I have few questions about the architecture and the implementation for this project.

First to setup the basis i will use c# ( .NET 3.5 ) and i want to explicitly use raw Sockets/AIO/Threads(No WCF at first as i do want to fine tune the server and clients to my needs ). Clients mostly subscribe to topics but may occasionally send command to the server and even publish data . Some clients may be publishers only as well.

  1. What do you think should be the basic building blocks of my server ( threads per client , iocp, .... ).

  2. Should client use the same NetworkStream to listen subscribed topics and send command/publish to the server? How to wait for data and at the same time write data to the stream , should this be done in the same thread ?

(sample code will be appreciated :) )

A: 
  1. I would use async sockets as much as possible as it would eliminate the need for you to manage your own thread pool for request handling.

  2. The client should use two streams - one for listing and another for sending. This would greatly simplify things on both the client and server side. Again, use async sockets to avoid having to manage multiple threads.

Just make sure to be careful managing locking with shared resources used by your async callbacks. If at all possible, avoid having shared resources as much as possible. Managine concurrent access to things is usually the worst part of any app like this.

Eric Petroelje
A: 

Have you checked out ActiveMQ? I believe it already does topics and C# has the ability to talk to it through their NMS API.

Joe The Software Developer
Yes it already provides that kind of service but i would like to learn more and understand the internal of writing efficient and scalable network server.
Dave
A: 

Look into I/O completion ports

Kumar