1 Replies - 1893 Views - Last Post: 05 August 2009 - 07:57 AM Rate Topic: -----

#1 bocsiboti   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-August 09

Fast Messages not sent through TcpClient

Posted 05 August 2009 - 07:40 AM


I am writing a server/client application and I have encountered a weird problem. The server handles several TCP connections and sometimes sends messages to the clients. Now, if I send these messages too "fast" they are not sent at all. However, if a Thread.Sleep(1000); command is introduced before sending a message everything works fine (except it is very slow). Maybe it is relevant that the Send() method is called by different threads , triggered by events (locking the communication object does not help). Here is the code:
public void Send(int id, string message) 
			StreamWriter writer = new StreamWriter(connections_[id].GetStream());
			// type of connections_ is Dictionary<int, TcpClient>


Is This A Good Question/Topic? 0
  • +

Replies To: Fast Messages not sent through TcpClient

#2 Core   User is offline

  • using System.Linq;
  • member icon

Reputation: 783
  • View blog
  • Posts: 5,101
  • Joined: 08-December 08

Re: Fast Messages not sent through TcpClient

Posted 05 August 2009 - 07:57 AM

In your situation I would recommend using the Close method for the StreamWriter instead of Flush, to ensure that the data will be correctly written.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1