Что-то совсем непонятно - возможно ошибка в программе на стороне ПК. Но не могу понять что не так (на C# пишу редко) - программа простая совсем.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.IO;
using cs_CRC;
namespace EchoTest
{
class Program
{
private static int port;
private static string server;
static TcpClient client;
static NetworkStream stream;
static byte[] rx;
static void Main(string[] args)
{
server = args[0];
port = int.Parse(args[1]);
rx = new byte[1024];
int error_counter=0;
int file_send_qty = int.Parse(args[2]);
client = new TcpClient();
try
{
Console.WriteLine("Connecting...");
client.Connect(server, port);
stream = client.GetStream();
Console.WriteLine(DateTime.Now.ToString()+">>Connectned.");
int file_send_count = 0;
while (file_send_count < file_send_qty)
{
byte[] data = File.ReadAllBytes("file_for_send");
uint crc = CRC.Crc32(data, 0, data.Length, 0);
uint sum = 0;
for (int i = 0; i<data.Length; i++)
sum+=data[i];
stream.Write(data, 0, data.Length);
do
{
System.Threading.Thread.Sleep(100);
} while (stream.DataAvailable==false);
byte[] echo = new byte[data.Length];
int echo_index = 0;
int read_bytes;
while (echo_index<data.Length) {
read_bytes = stream.Read(echo, echo_index, echo.Length-echo_index);
echo_index += read_bytes;
}
bool test_complete = true;
error_counter=0;
for (int i=0; i<echo.Length; i++) {
byte tmp = echo[i];
//tmp^=0xFF;
if (data[i]!=tmp)
{
test_complete=false;
error_counter++;
}
}
if (test_complete==true) {
file_send_count++;
Console.WriteLine("File send counter -- " + file_send_count.ToString());
}
else
{
file_send_count=file_send_qty;
Console.WriteLine("Echo ERROR.");
client.Close();
}
}
client.Close();
Console.WriteLine("Connection closed.");
Console.WriteLine();
Console.WriteLine("Press any key.");
Console.WriteLine();
Console.ReadKey();
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
}
}
}
}