İbrahim Akgün
İbrahim Akgün

Reputation: 1577

Thread Management in C# Socket Programming

I have got an TCP Socket Application that client side sending huge string messages to server at same time.And server getting this messages writing them into Access DB.So if there are so many clients server side can not handle each client properly and sometime server closing itself.

Is there any way tell client's thread before send message wait for queue if there is another client currently in queue? With this server don't need to be handle for example 30 client's demand at same time.

For example;

  1. Client sends message => Server processing 1 client's demand
  2. Client is waiting for 1 client's demands for complete than 2 Client sends message => Server processing 1 client's demand
  3. Client is waiting for 2 client's demands for complete.

My problem is appears when I use access db. While opening access connection saving data into tables and closing db is taking time and server go haywire :) If I don't use access db I can get huge messages with no problem.

Upvotes: 0

Views: 845

Answers (2)

DarthVader
DarthVader

Reputation: 55102

Yes, you can do that however that s not the most efficient way of doing it. Your scheme is single threaded.

What you want to do is create a threadpool and accept messages from multiple clients and process them as seperate threads. If that s too complicated. You can have a producer consumer queue within your server, all incoming messages will be stored in a queue while your server will be processing them first come first serve basis.

Upvotes: 3

zmbq
zmbq

Reputation: 39039

I think you should consider using a web server for your application, and replacing your protocol with HTTP. Instead of sending huge strings on a TCP stream, just POST the string to the server using your favorite HttpClient class.

By moving to HTTP you more or less solve all your performance issues. The web server already knows how to handle multiple long requests so you don't need to worry about that. Since you're sending big strings, the HTTP overhead is not going to affect your performance.

Upvotes: 0

Related Questions