S
Safiiru no Baka
Hi i'm running a simple test.
App 1 (sender), this is a thread:
===========================================================
ASCIIEncoding encoder = new ASCIIEncoding();
Byte[] hugeData = new Byte[5000];
for (int i = 0; i < hugeData.Length; i++)
{
hugeData = 88;
}
while (true)
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(new
IPEndPoint(IPAddress.Parse(listenTcpAddress), sendTcpPort));
tcpClient.GetStream().Write(hugeData, 0,
hugeData.Length);
tcpClient.Close();
}
===========================================================
App2 (listener) also in a thread:
===========================================================
TcpListener tcpListener = new TcpListener(new
IPEndPoint(IPAddress.Parse(listenTcpAddress), listenTcpPort));
tcpListener.Start();
while (runListener)
{
if (tcpListener.Pending())
{
TcpClient tcpClient =
tcpListener.AcceptTcpClient();
Stream s = tcpClient.GetStream();
Byte[] buffer = new Byte[5000];
int bytes = s.Read(buffer, 0, buffer.Length);
string data = Encoding.ASCII.GetString(buffer, 0,
bytes);
tcpClient.Close();
}
Thread.Sleep(0);
}
===========================================================
After running for a few seconds, the App 1 crashes with a "No
connection could be made because the target machine actively refused
it" exception on tcpClient.Connect.
I am not sure what to proceed with... any help would be greatly
appreciated. Thanks.
App 1 (sender), this is a thread:
===========================================================
ASCIIEncoding encoder = new ASCIIEncoding();
Byte[] hugeData = new Byte[5000];
for (int i = 0; i < hugeData.Length; i++)
{
hugeData = 88;
}
while (true)
{
TcpClient tcpClient = new TcpClient();
tcpClient.Connect(new
IPEndPoint(IPAddress.Parse(listenTcpAddress), sendTcpPort));
tcpClient.GetStream().Write(hugeData, 0,
hugeData.Length);
tcpClient.Close();
}
===========================================================
App2 (listener) also in a thread:
===========================================================
TcpListener tcpListener = new TcpListener(new
IPEndPoint(IPAddress.Parse(listenTcpAddress), listenTcpPort));
tcpListener.Start();
while (runListener)
{
if (tcpListener.Pending())
{
TcpClient tcpClient =
tcpListener.AcceptTcpClient();
Stream s = tcpClient.GetStream();
Byte[] buffer = new Byte[5000];
int bytes = s.Read(buffer, 0, buffer.Length);
string data = Encoding.ASCII.GetString(buffer, 0,
bytes);
tcpClient.Close();
}
Thread.Sleep(0);
}
===========================================================
After running for a few seconds, the App 1 crashes with a "No
connection could be made because the target machine actively refused
it" exception on tcpClient.Connect.
I am not sure what to proceed with... any help would be greatly
appreciated. Thanks.