M
Markgoldin
Here is my code to create a TCP listener:
file name DataAdapterLauncher.cs
public static TcpListener tcpl;
IPEndPoint ipe = new IPEndPoint(IPAddress.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 DataAdapterLauncher.cs
private volatile bool monitorPort = true;
byte[] byteReadStream = null; // holds the data in byte buffer
TcpClient tcpc = DataAdapterLauncher.tcpl.AcceptTcpClient(); //accept
connection
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;
}
}
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 DataAdapterLauncher.cs
public static TcpListener tcpl;
IPEndPoint ipe = new IPEndPoint(IPAddress.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 DataAdapterLauncher.cs
private volatile bool monitorPort = true;
byte[] byteReadStream = null; // holds the data in byte buffer
TcpClient tcpc = DataAdapterLauncher.tcpl.AcceptTcpClient(); //accept
connection
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;
}
}
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.