私は、ソケットと類似しており、非常に単純なファイルの受信を書いた:
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
EndPoint endpoint = new IPEndPoint(IPAddress.Any, 2442);
socket.Bind(endpoint);
socket.Listen(10000);
System.Console.WriteLine("Waiting for incoming data on *:2442");
Socket client = socket.Accept();
byte[] buffer = new byte[2000];
List<byte> wholeThing = new List<byte>();
int count = 0;
do {
count = client.Receive(buffer);
for (int i = 0 ; i < count ; i++)
wholeThing.Add(buffer[i]);
System.Console.Write("*");
} while (count > 0);
System.Console.WriteLine(Environment.NewLine + "Received {0} bytes of data", wholeThing.Count);
File.WriteAllBytes(Application.StartupPath + "\\receivedFile", wholeThing.ToArray());
は、送信者のコードはこのように見えた:
byte[] fileData = File.ReadAllBytes(fileName);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(IPAddress.Parse(targetip), 2442);
int offset = 0;
do {
try {
offset = socket.Send(fileData, offset, fileData.Length - offset, SocketFlags.None);
} catch {
socket.Close();
throw;
}
} while (offset < fileData.Length);
ありがとう=) –