【求助】C#socket传输文件问题
这个是找了好久唯一一个不报错的C#传文件源码,但是注释较少,还是遇到些问题,再此求助大佬
源码: //文件发送 publicvoid Send(IPEndPoint ip, string path)
{
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sock.Connect(ip);
using (FileStream reader = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None))
{
long send = 0L, length = reader.Length;
sock.Send(BitConverter.GetBytes(length));
string fileName = Path.GetFileName(path);
sock.Send(Encoding.Default.GetBytes(fileName));
Console.WriteLine("Sending file:" + fileName + ".Plz wait...");
byte[] buffer = new byte;
int read, sent;
//断点发送 在这里判断设置reader.Position即可
while ((read = reader.Read(buffer, 0, BufferSize)) != 0)
{
sent = 0;
while ((sent += sock.Send(buffer, sent, read, SocketFlags.None)) < read)
{
send += (long)sent;
//Console.WriteLine("Sent " + send + "/" + length + ".");//进度
}
}
Console.WriteLine("Send finish.");
}
}
调用此接受方法时报以下错误:
请问大佬应如何修改 欢迎各位大佬发表高见{:301_997:} Send(new IPEndPoint(IPAddress.Parse("ip"),端口),"文件路径"); wangsheng66 发表于 2021-8-22 19:51
Send(new IPEndPoint(IPAddress.Parse("ip"),端口),"文件路径");
请问大佬要这个要包含端口吗
页:
[1]