Click here to Skip to main content
15,886,362 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: How To lock date function in .Net Pin
Pete O'Hanlon1-Feb-16 5:04
mvePete O'Hanlon1-Feb-16 5:04 
AnswerRe: How To lock date function in .Net Pin
Gerry Schmitz1-Feb-16 6:14
mveGerry Schmitz1-Feb-16 6:14 
QuestionProblem with sqlite and entity framework. please help! Pin
neodeaths30-Jan-16 19:28
neodeaths30-Jan-16 19:28 
AnswerRe: Problem with sqlite and entity framework. please help! Pin
Sascha Lefèvre30-Jan-16 20:59
professionalSascha Lefèvre30-Jan-16 20:59 
AnswerRe: Problem with sqlite and entity framework. please help! Pin
Dave Kreskowiak31-Jan-16 3:41
mveDave Kreskowiak31-Jan-16 3:41 
Questiondesktop app using java prodramming language Pin
Member 1229118627-Jan-16 7:30
Member 1229118627-Jan-16 7:30 
AnswerRe: desktop app using java prodramming language Pin
Pete O'Hanlon27-Jan-16 7:45
mvePete O'Hanlon27-Jan-16 7:45 
Question[C# 2008] TcpClient Close method does not close TCP connection Pin
steve_949661324-Jan-16 23:44
professionalsteve_949661324-Jan-16 23:44 
Greetings to all,
my application runs in a Windows Embedded Compact 7 device and it uses Compact Framework 3.5.
It establishes a TCP connection to a PLC and exchanges data with it.

I open the connection in this way:
C#
mTcpCli = new TcpClient()
mTcpCli.Connect(mIp, mPort);
MBStream = mTcpCli.GetStream();

Then I start the communication thread.
If there is a communication error, I close the connection and I re-open it with the above code.
To close the connection I do ALL this:
C#
MBStream.Close();
MBStream.Dispose();
mTcpCli.Client.Close();
mTcpCli.Close();
((IDisposable)mTcpCli).Dispose();
if (mTcpCli != null)
{
  mTcpCli = null;
}

but it seems not to be enough...

Suppose the communication error is cable disconnected, absolutely no way to communicate.
When I re-open the connection the instruction:
C#
mTcpCli.Connect(mIp, mPort);

should give an exception (SocketException) but it doesn't.
Until the communication is interrupted, I could say that it is not a very serious problem because the application tries to communicate with the PLC, it fails and the "close-reopen connection" loop restart (with 10 seconds of pause between one retries).

The true problem is when the communication error is solved: I re-connect the cable.
In this situation the instruction:
C#
mTcpCli.Connect(mIp, mPort);

doesn't give any exception, and should not, but it doesn't establish a connection so the application tries to communicate with the PLC, it fails and retries the connection.
I takes 4-5 attempts to establish a TRUE connection, almost a minute.

I looked for a solution in this and other forum and in MSDN and I found that there is a bug in the TcpClient Close method but the soution, close also the network stream, doesn't work.
I tried to close and dispose all I could with no result.

When I close the connection I need to be sure it is closed and I can't succesfully open it when the cable is disconnected!

Anybody can help me?

Thank you in advance.

Steve
AnswerRe: [C# 2008] TcpClient Close method does not close TCP connection Pin
Richard MacCutchan24-Jan-16 23:58
mveRichard MacCutchan24-Jan-16 23:58 
GeneralRe: [C# 2008] TcpClient Close method does not close TCP connection Pin
steve_949661325-Jan-16 1:56
professionalsteve_949661325-Jan-16 1:56 
GeneralRe: [C# 2008] TcpClient Close method does not close TCP connection Pin
Richard MacCutchan25-Jan-16 2:33
mveRichard MacCutchan25-Jan-16 2:33 
GeneralRe: [C# 2008] TcpClient Close method does not close TCP connection Pin
steve_949661325-Jan-16 2:59
professionalsteve_949661325-Jan-16 2:59 
QuestionLimiting GOOGLE CHROME APPLICATION? Pin
Member 1227913922-Jan-16 5:46
Member 1227913922-Jan-16 5:46 
AnswerRe: Limiting GOOGLE CHROME APPLICATION? Pin
Richard MacCutchan22-Jan-16 6:33
mveRichard MacCutchan22-Jan-16 6:33 
AnswerRe: Limiting GOOGLE CHROME APPLICATION? Pin
Eddy Vluggen22-Jan-16 6:34
professionalEddy Vluggen22-Jan-16 6:34 
QuestionRe: Limiting GOOGLE CHROME APPLICATION? Pin
Paul Conrad23-Jan-16 11:56
professionalPaul Conrad23-Jan-16 11:56 
AnswerRe: Limiting GOOGLE CHROME APPLICATION? Pin
Member 1227913924-Jan-16 13:32
Member 1227913924-Jan-16 13:32 
QuestionBandwidth limit for application google chrome. Pin
Member 1227913921-Jan-16 8:05
Member 1227913921-Jan-16 8:05 
AnswerRe: Bandwidth limit for application google chrome. Pin
Gerry Schmitz21-Jan-16 8:22
mveGerry Schmitz21-Jan-16 8:22 
AnswerRe: Bandwidth limit for application google chrome. Pin
Dave Kreskowiak21-Jan-16 11:29
mveDave Kreskowiak21-Jan-16 11:29 
AnswerRe: Bandwidth limit for application google chrome. Pin
jschell2-Feb-16 13:22
jschell2-Feb-16 13:22 
QuestionCould Not resolve the com reference Pin
Member 119030628-Jan-16 0:17
Member 119030628-Jan-16 0:17 
AnswerRe: Could Not resolve the com reference Pin
Richard MacCutchan8-Jan-16 1:10
mveRichard MacCutchan8-Jan-16 1:10 
GeneralRe: Could Not resolve the com reference Pin
Member 119030628-Jan-16 1:24
Member 119030628-Jan-16 1:24 
SuggestionRe: Could Not resolve the com reference Pin
Richard Deeming8-Jan-16 3:51
mveRichard Deeming8-Jan-16 3:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.