idrozdov

Hi all.

I have application, that listens 10-12 different ports(this is different TcpListeners). On each port connects client(at this time only one). After that runs new thread for this client and application starts to collect data from client(~ 1 message in 4 seconds) and write it to MS SQL 2005 database.
But I have next problem: after 6-8 hours working, it stops write data to database(as I can analyse it, from all threads simulatenously) and my tries to connect on some port, listeners don't listen it.

Can somebody help me with this



Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

RizwanSharp

In 8-10 hours how many clients do connect or disconnect

Can you please show the part of code where you are acceptoing clients and creating threads ti get work done.

+ I would recommend using Asynchronous Sockets than creating new thread for each client.

Best Regards,

Rizwan aka RizwanSharp






Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

idrozdov

I have only 10-12 or less clients. All data processing stops at same moment(less than 1 minute)

while (true)
{
try
{
tListener = ie.Current;
if (tListener.Pending())
{
tClient = tListener.AcceptTcpClient();
adress = tClient.Client.RemoteEndPoint.ToString();
tmp = adress.Substring(0, adress.IndexOf(':'));
if (ipFilter.containIP(tmp))
{
cdi = CD.getCDByIP(tmp);
if (cdReaders.ContainsKey(adress))
{
cdReader = (CDReader)cdReaders[adress];
if (!cdReader.IsWorking)
{
cdReaders.Remove(cdReader.getAdress);
cdReader = new CDReader(tClient, CD.getCDIP(adress));
cdReaders.Add(adress, cdReader);
}
}
else
{
cdReader = new CDReader(tClient, CD.getCDByIP(tmp));
cdReaders.Add(tClient.Client.RemoteEndPoint.ToString(), cdReader);
}
}
}
}
catch (Exception ex)
{
...
}
}

Constructor CDReader:
public CDReader(TcpClient tClient,CashDeskItem cdi)
{
try
{
m_TcpClient = tClient;
m_TcpClient.ReceiveTimeout = m_ReceaveTimeout;
mcdParser = new MCD(cdi);
m_ReaderThread = new Thread(new ThreadStart(ReaderThread));
m_ReaderThread.Start();
}
catch (Exception ex)
{
...
}
}




Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

Mariya Atanasova - MSFT

It is possible that you're exhausting all the available ports. What is the result of "netstat -a"
Do you get any exceptions How do you choose on which port you're making the connection

Mariya





Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

idrozdov

No, I use only 12 ports & I know that I haven't reconnects.(in log)




Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

Mariya Atanasova - MSFT

Can you get a System.Net trace log so we can see what is happening

Instructions on how to get a trace log are here: http://blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspx

Mariya





Re: .NET Framework Networking and Communication TcpListener stops listen for new connections

idrozdov

Thanks all for your help, I found an error in some other place.. :(