大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
'缓冲区长度
成都创新互联自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
下载,直接通过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();
}
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
'初始化界面
只需要发应用程序就行了, 就是后缀名为.exe的..... 其他东西都不用发的.