Aplikacije rade na sledeci nacin:
Klijentska aplikacija na svakih 100mS proziva server.
Server ispisuje podatke koje je dobio od klijenta i kao odgovor posalje niz od 17000 bajtova.
Klijent proverava da li je 15395 bajt tog niza == 14
Ako jeste ispise OK.
Ako nije povecava brojac greske.
E sad kad pustim obe aplikacije, softver jedno vreme (5 minuta) radi dobro, a potom krene da se povecava brojac greske, tj. 15395 bajt niza postaje 0. Nakon sto se prvi put pojavi greska, njena frekvencija pojavljivanja raste.
Prilikom testiranja, pokrenuo sam obe aplikacije na istom racunaru.
Kako da resim problem, da se ne pojavljuju greske?
Da li je mozda problem u kolicini bajtova koji se salju od strane servera?
hvala
Server:
Code:
TcpListener TCPIPServer = new TcpListener(IPAddress.Any, 12200);
TCPIPServer.Start();
bool BrokenConn= false;
Byte[] byteComData = new Byte[17000];
string strComData = null;
while (true)
{
int i = 0;
BrokenConn= false;
TcpClient TCPIPKlijent = TCPIPServer.AcceptTcpClient();
NetworkStream stream = TCPIPKlijent.GetStream();
while (BrokenConn== false)
{
i = stream.Read(byteComData, 0, byteComData.Length);
strComData = System.Text.Encoding.ASCII.GetString(byteComData, 0, i);
strComData = strComData.TrimEnd('\n', '\r');
string Parametar = (strComData.Substring(1, strComData.Length - 1)).TrimEnd('\n', '\r');
Console.WriteLine(Parametar);
byte[] tmpInt = new byte[17000];
tmpInt[0] = 56;
tmpInt[1] = 78;
tmpInt[2] = 122;
tmpInt[3] = 166;
tmpInt[15395] = 14;
stream.Write(tmpInt, 0, 16200);
}
}
TcpListener TCPIPServer = new TcpListener(IPAddress.Any, 12200);
TCPIPServer.Start();
bool BrokenConn= false;
Byte[] byteComData = new Byte[17000];
string strComData = null;
while (true)
{
int i = 0;
BrokenConn= false;
TcpClient TCPIPKlijent = TCPIPServer.AcceptTcpClient();
NetworkStream stream = TCPIPKlijent.GetStream();
while (BrokenConn== false)
{
i = stream.Read(byteComData, 0, byteComData.Length);
strComData = System.Text.Encoding.ASCII.GetString(byteComData, 0, i);
strComData = strComData.TrimEnd('\n', '\r');
string Parametar = (strComData.Substring(1, strComData.Length - 1)).TrimEnd('\n', '\r');
Console.WriteLine(Parametar);
byte[] tmpInt = new byte[17000];
tmpInt[0] = 56;
tmpInt[1] = 78;
tmpInt[2] = 122;
tmpInt[3] = 166;
tmpInt[15395] = 14;
stream.Write(tmpInt, 0, 16200);
}
}
Code:
TcpClient simpleTcp = null;
NetworkStream tcpStream = null;
int bytesToRead = 0, nextReadCount, rc;
int bufferSize = 17000;
IPAddress MyIPAddress;
int BrojGresaka=0;
IPAddress.TryParse("192.168.1.11", out MyIPAddress);
byte[] sendBuffer = new byte[bufferSize], receiveBuffer = new byte[bufferSize], byteCount;
// Create the client and indicate the server to connect to
Console.WriteLine("TCP client: Creating the client and indicate the server to connect to...");
simpleTcp = new TcpClient("192.168.1.11", 12200);
// Retrieve the NetworkStream so we can do Read and Write
Console.WriteLine("TCP client: Retrieving the NetworkStream so we can do Read and Write...");
tcpStream = simpleTcp.GetStream();
while (true)
{
tcpStream.Write(Encoding.ASCII.GetBytes("D63449061600"), 0, 12);
rc = tcpStream.Read(receiveBuffer, 0, bufferSize);
Console.WriteLine(receiveBuffer[15395]);
if (receiveBuffer[15395] == 14)
{
Console.WriteLine(DateTime.Now.ToString() + " OK!, Broj gresaka:" + BrojGresaka.ToString());
}
else
{
BrojGresaka++;
Console.WriteLine("Greska br:" + BrojGresaka.ToString());
}
Thread.Sleep(100);
}
TcpClient simpleTcp = null;
NetworkStream tcpStream = null;
int bytesToRead = 0, nextReadCount, rc;
int bufferSize = 17000;
IPAddress MyIPAddress;
int BrojGresaka=0;
IPAddress.TryParse("192.168.1.11", out MyIPAddress);
byte[] sendBuffer = new byte[bufferSize], receiveBuffer = new byte[bufferSize], byteCount;
// Create the client and indicate the server to connect to
Console.WriteLine("TCP client: Creating the client and indicate the server to connect to...");
simpleTcp = new TcpClient("192.168.1.11", 12200);
// Retrieve the NetworkStream so we can do Read and Write
Console.WriteLine("TCP client: Retrieving the NetworkStream so we can do Read and Write...");
tcpStream = simpleTcp.GetStream();
while (true)
{
tcpStream.Write(Encoding.ASCII.GetBytes("D63449061600"), 0, 12);
rc = tcpStream.Read(receiveBuffer, 0, bufferSize);
Console.WriteLine(receiveBuffer[15395]);
if (receiveBuffer[15395] == 14)
{
Console.WriteLine(DateTime.Now.ToString() + " OK!, Broj gresaka:" + BrojGresaka.ToString());
}
else
{
BrojGresaka++;
Console.WriteLine("Greska br:" + BrojGresaka.ToString());
}
Thread.Sleep(100);
}
---------------------
****
< 9 9 > My name
..( o ).. is
. . -- . .MX86251 ?
****
< 9 9 > My name
..( o ).. is
. . -- . .MX86251 ?