资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net文件发送 vb文件怎么发送

vb.net udpclient 发送大文件循环问题

'缓冲区长度

成都创新互联自2013年起,先为平罗等服务建站,平罗等地企业,进行企业商务咨询服务。为平罗企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

Const BufLen As Integer=800

'包发送间隔

Const Interval As Integer=62

'缓冲区

Dim buf As Byte()=Nothing

'远程(目的)网络端点

Dim remoteep As IPEndPoint=Nothing

'如果你已将s定义为类的成员变量(实例或共享),注释掉下面这句

Dim s As UdpClient=Nothing

Dim willread As Integer

Try

buf=New Byte(BufLen-1) {}

s=New UdpClient()

' TextBox1.Text包含远程(目的)主机的IP地址

' TextBox2.Text包含远程(目的)主机的端口号

remoteep=New IPEndPoint(IPAddress.Parse(Trim(TextBox1.Text)),CInt(TextBox2.Text))

' Label2.Text包含要发送的文件的路径

Using fs As New FileStream(Label2.Text,FileMode.Open,FileAccess.Read)

While fs.Positionfs.Length

willread=BufLen

If fs.Length-fs.PositionBufLen Then

willread=CInt(fs.Length-fs.Position)

End If

fs.Read(buf,0,willread)

s.Send(buf,willread,remoteep)

Thread.Sleep(Interval)

End While

End Using

Catch ex As Exception

MsgBox(ex.ToString())

Finally

If s IsNot Nothing Then

s.Close()

End If

End Try

求大神指点 vb.net 怎么发送大文件 我用 UdpClient 的Send只能发送5000字节以下的

下载,直接通过url读取文件,然后Response.OutputStream.Write()数据

下面提供个下载的静态方法,是C#的,供参考:

/// summary

/// 下载文件

/// /summary

/// param name="fileName"下载的文件名称(包括扩展名)/param

/// param name="filePath"下载文件的绝对路径/param

public static void DownFile(string fileName, string filePath)

{

//打开要下载的文件,并把该文件存放在FileStream中                

System.IO.FileStream Reader = System.IO.File.OpenRead(filePath);

//文件传送的剩余字节数:初始值为文件的总大小                

long Length = Reader.Length;

HttpContext.Current.Response.Buffer = false;

HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");

HttpContext.Current.Response.ContentType = "application/octet-stream";

HttpContext.Current.Response.Charset = "utf-8";

HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName));

HttpContext.Current.Response.AddHeader("Content-Length", Length.ToString());

byte[] Buffer = new Byte[10000];//存放欲发送数据的缓冲区                

int ByteToRead; //每次实际读取的字节数               

while (Length  0)

{    

//剩余字节数不为零,继续传送                    

if (HttpContext.Current.Response.IsClientConnected)

{    

//客户端浏览器还打开着,继续传送                        

ByteToRead = Reader.Read(Buffer, 0, 10000);                   //往缓冲区读入数据                        

HttpContext.Current.Response.OutputStream.Write(Buffer, 0, ByteToRead);    

//把缓冲区的数据写入客户端浏览器                        

HttpContext.Current.Response.Flush(); //立即写入客户端                        

Length -= ByteToRead;//剩余字节数减少                            }

else

{                         

//客户端浏览器已经断开,阻止继续循环                        

Length = -1;

}

}                //关闭该文件               

Reader.Close();

}

vb.net怎么实现串口传输文件

Imports System

Imports System.IO.Ports

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'获取计算机有效串口

Dim ports As String() = SerialPort.GetPortNames() '必须用命名空间,用SerialPort,获取计算机的有效串口

Dim port As String

For Each port In ports

portnamebox.Items.Add(port) '向combobox中添加项

Next port

'初始化界面

VB.net的作品如果完成要发给别人用的话,要发哪些文件给别人就可以啦

只需要发应用程序就行了, 就是后缀名为.exe的..... 其他东西都不用发的.


本文名称:vb.net文件发送 vb文件怎么发送
地址分享:http://cdkjz.cn/article/docdieh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220