Re: TCP listener

Tech-Archive recommends: Fix windows errors by optimizing your registry



Here is my modified code:
while (monitorPort)
{
byteReadStream = new byte[tcpc.Available]; //allocate space for data
tcpc.GetStream().Read(byteReadStream, 0, tcpc.Available);
//read data into byte array
if (byteReadStream != null)
{
monitorPort = false;
}
System.Console.WriteLine("In the loop");
}

The change is
System.Console.WriteLine("In the loop");

When I send data to the listener I see "In the loop" two times, after
disconnecting in starts writing "In the loop" without stoping.

Any idea why it gets into the loop after disconnecting?

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin@xxxxxxxxx> wrote in
message
news:dda5cb03-7581-492c-91aa-17813cea7eb3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Jul 18, 3:04 pm, "Markgoldin" <markgoldin_2...@xxxxxxxxx> wrote:
Like I said, I am not a c# programmer, but I need a little c# code for my
application.
I understand your commens though and will look into it.
But for now it's fine with one connection only however the following

TcpClient tcpc = DataAdapterLauncher.tcpl.AcceptTcpClient(); //accept

connection
How do you return to the above line?
If you never do, you can only create one connection

is the reason of CPU going 100% after a client closes connection?

no, of course not, that line is executed AT the connection time, then
you enter in the while loop
do this, copy your code in a win or console project and see where it
gets stuck


.



Relevant Pages

  • Re: TCP listener
    ... This loop is required because of the main purpose of the program I am trying ... I am using the push server product's .Net sample and trying to modify it ... that it only works untill I close connection to the c# listener. ... private volatile bool monitorPort = true; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCP listener
    ... private volatile bool monitorPort = true; ... It works fine as long as a client keeps connection. ... You didn't post a concise-but-complete code sample, ... it's certainly possible that the loop you posted for some ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: TCP listener
    ... private volatile bool monitorPort = true; ... It works fine as long as a client keeps connection. ... assuming that's the literal code, "byteReadStream" is _never_ going to be null, and so that loop will always execute the contained block exactly once before exiting ...
    (microsoft.public.dotnet.languages.csharp)
  • SSIS - Error Messages when looping through Excel Files
    ... What's the trick to use a Foreach File in Folder loop when looping through ... Now if I have my XL Connection manager set to a specific file, ...
    (microsoft.public.sqlserver.dts)
  • Re: Changing connection information on OLEDB connection
    ... What I would do is set a breakpoint on the "On Each Iteration Of The Loop" event. ... I would then set a watch on the variable to make sure that the connection string is being set properly. ... When I run the package, I just get the first server's data twice, it ... but the second loop around it doesn't seem to be working. ...
    (microsoft.public.sqlserver.dts)