Здравствуйте, Stuw, Вы писали:
Спасибо за совет. серверную часть передаелал пока что так:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace ConsoleApplication1
{
[Serializable]
public class FileDetalis
{
public string FileType = "";
public int FileSize = 0;
}
class Program
{
private static int localPort = 5005;
private static UdpClient rUdpClient = new UdpClient(localPort);
private static IPEndPoint rIpEnd = null;
private static byte[] rByte;
private static string fSize;
private static FileStream fs;
private static FileDetalis fdet;
static void Main(string[] args)
{
Console.WriteLine("Ждем получения файла");
Thread p = new Thread(new ThreadStart(ReceivedFile));
p.Start();
Console.ReadLine();
}
private static string Type;
private static string Size;
private static void GetFileInfo()
{
rByte = rUdpClient.Receive(ref rIpEnd);
Console.WriteLine("*****Информация о файле*****");
fSize = Encoding.ASCII.GetString(rByte);
Type = fSize.Substring(0, 3);
Size = fSize.Substring(3, fSize.Length - 3);
Console.WriteLine(Type+"; "+Size);
fdet = new FileDetalis();
fdet.FileType = Type;
fdet.FileSize = Convert.ToInt32(Size);
}
private static TcpClient client;
public static void ReceivedFile()
{
try
{
TcpListener listner = new TcpListener(5002);
listner.Start();
while (true)
{
client = listner.AcceptTcpClient();
if (client.Connected)
{
Thread tt = new Thread(new ThreadStart(Receiv));
tt.Start();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
static void Receiv()
{
try
{
GetFileInfo();
NetworkStream st = client.GetStream();
rByte = new byte[Convert.ToInt32(Size)];
st.Read(rByte, 0, rByte.Length);
Console.WriteLine("Сохраняем присланый файл");
fs = new FileStream("temp." + Type, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
fs.Write(rByte, 0, rByte.Length);
Console.WriteLine("Файл сохранен");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
fs.Close();
client.Close();
}
}
}
}
В принципе все работает. Но мне кажется (а точнее так оно и есть) мой код жутко корявый. Думаю многие сделалибы Намного красивее и легче
Спасибо за Совет!

... << RSDN@Home 1.1.4 stable SR1 rev. 568>>