Here is my code to create a TCP listener:
file name DataAdapterLaun cher.cs
public static TcpListener tcpl;
IPEndPoint ipe = new IPEndPoint(IPAd dress.Parse("0. 0.0.0"), 1024);//listen
on all local addresses
tcpl = new TcpListener(ipe );
tcpl.Stop();
tcpl.Start();
and that code handles data:
file name DataAdapterLaun cher.cs
private volatile bool monitorPort = true;
byte[] byteReadStream = null; // holds the data in byte buffer
TcpClient tcpc = DataAdapterLaun cher.tcpl.Accep tTcpClient(); //accept
connection
while (monitorPort)
{
byteReadStream = new byte[tcpc.Available]; //allocate space for data
tcpc.GetStream( ).Read(byteRead Stream, 0, tcpc.Available) ;
//read data into byte array
if (byteReadStream != null)
{
monitorPort = false;
}
}
Please note, I am not a .Net developer, so you might see something strange
in my code.
It does work though but with one problem, as soon as a client disconnects
from my listener, the CPU usage goes up 100% to my exe
and no connections can be made to it.
Any idea?
Thanks for any help.
file name DataAdapterLaun cher.cs
public static TcpListener tcpl;
IPEndPoint ipe = new IPEndPoint(IPAd dress.Parse("0. 0.0.0"), 1024);//listen
on all local addresses
tcpl = new TcpListener(ipe );
tcpl.Stop();
tcpl.Start();
and that code handles data:
file name DataAdapterLaun cher.cs
private volatile bool monitorPort = true;
byte[] byteReadStream = null; // holds the data in byte buffer
TcpClient tcpc = DataAdapterLaun cher.tcpl.Accep tTcpClient(); //accept
connection
while (monitorPort)
{
byteReadStream = new byte[tcpc.Available]; //allocate space for data
tcpc.GetStream( ).Read(byteRead Stream, 0, tcpc.Available) ;
//read data into byte array
if (byteReadStream != null)
{
monitorPort = false;
}
}
Please note, I am not a .Net developer, so you might see something strange
in my code.
It does work though but with one problem, as soon as a client disconnects
from my listener, the CPU usage goes up 100% to my exe
and no connections can be made to it.
Any idea?
Thanks for any help.
Comment