Здравствуйте, ребята, я получаю эту ошибку, пожалуйста, смотрите вложение >> Index and count must refer to a location within the buffer. Parameter name: bytes
Когда я использую отладчик я не получаю эту ошибку, и все идет хорошо, я не могу понять, что это за ошибка
это мой код сервера:
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, 27015);
Socket sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
sck.Bind(ipEnd);
sck.Listen(100);
Socket clientSocket = sck.Accept();
string[] fNames = new string[3];
fNames[0] = "01.jpg";
fNames[1] = "02.jpg";
fNames[2] = "03.jpg";
string filePath = "D:\\";
byte[] FilesCount = BitConverter.GetBytes(fNames.Count());
clientSocket.Send(FilesCount);
for (int i = 0; i < fNames.Count(); i++)
{
byte[] fileNameByte = Encoding.ASCII.GetBytes(fNames[i]);
byte[] fileData = File.ReadAllBytes(filePath + fNames[i]);
byte[] clientData = new byte[4 + fileNameByte.Length + fileData.Length];
byte[] fileNameLen = BitConverter.GetBytes(fileNameByte.Length);
fileNameLen.CopyTo(clientData, 0);
fileNameByte.CopyTo(clientData, 4);
fileData.CopyTo(clientData, 4 + fileNameByte.Length);
clientSocket.Send(clientData);
}
clientSocket.Close();
И Клиент:
Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
clientSock.Connect(IPAddress.Parse("46.49.70.30"), 27015);
byte[] clientData = new byte[1024 * bt];
string receivedPath = "D:/df/";
byte[] FileQuantityByte = new byte[1024];
clientSock.Receive(FileQuantityByte);
int FileQuantity = BitConverter.ToInt32(FileQuantityByte, 0);
for (int i = 0; i < FileQuantity; i++)
{
int receivedBytesLen = clientSock.Receive(clientData);
int fileNameLen = BitConverter.ToInt32(clientData, 0);
string fileName = Encoding.ASCII.GetString(clientData, 4, fileNameLen);
//Console.WriteLine("Client:{0} connected & File {1} started received.", clientSock.RemoteEndPoint, fileName);
BinaryWriter bWrite = new BinaryWriter(File.Open(receivedPath + fileName, FileMode.Append));
bWrite.Write(clientData, 4 + fileNameLen, receivedBytesLen - 4 - fileNameLen);
//Console.WriteLine("File: {0} received & saved at path: {1}", fileName, receivedPath);
bWrite.Close();
}
clientSock.Close();
РЕДАКТИРОВАТЬ: http://imageshack.us/f/202/errbk.jpg/