Dear .Net Developers, I need some help. I am developing network client-server applications using TCP/IP socket technique and C#. I need to distribute the data located in XML file from server application to several subscribers apps: console windows apps and web apps. I wrote server applications using asynchronous calls technique. Everything is working well, but I have problem: if i run a lot of client applications, some data is lost during distribution. I fill like it is TCP/IP buffer overload, because if i run more apps then more data lost, but i am using CallBack method and I'm checking the previous result of sending (I save the result in currentAsynchResult to check the delivery, but it's not working for me. Here is some code:
Method
static void SendToAll(string _msg)
{
foreach (ClientInfo _client in clientList)
{
Data msgToSend = new Data();
msgToSend.cmdCommand = Command.Message;
if (_client.strName == "Bill")
{
try
{
msgToSend.strName = "Bill";
msgToSend.strMessage = _msg;
byte[] byteData = msgToSend.ToByte();
currentClient = _client;
_client.socket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnBroadcast), currentAsynchResult);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
CallBack method:
static void OnBroadcast(IAsyncResult ar)
{
if (ar == currentAsynchResult)
{
try
{
currentClient.socket.EndSend(ar);
}
catch (ObjectDisposedException)
{ }
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
Using foreach to send the data:
static void StartDistributeXML()
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
SendtToAll(node.Attributes["text"].InnerText);
}
}
My idea is: 1. to check the CallBack method (may be my example is not correct) 2. To write some buffer for sending. 3. to check the details about sending packet (packet size, packet type , etc) - but i do not know how to implement it. Could please suggest me the solution? I am able to provide more code if needed.