大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
private void MyPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
创新互联是一家专业提供城厢企业网站建设,专注与网站制作、成都网站建设、H5建站、小程序制作等业务。10年已为城厢众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。
public static boolean isNumeric(String str){
if(str.matches("//d*"){
return true;
}else{
return false;
}
}
'缓冲区长度
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
服务器先进行
Bind ()绑定服务器的端口
然后BeginReceive接受客户端发送的数据
客户端Bind ()绑定客户端接受和发送数据的端口
SendTo()来发送数据就可以
不需要进行BeginConnect,因为UDP不需要连接
给你个udp多播例子,广播不是很清楚,呵呵
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Inherits System.Windows.Forms.Form
Dim port As String
Dim ipadd As String
Dim ipend As IPEndPoint
Dim sendudp As New UdpClient()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
Dim ipadress As IPAddress
ipadress = IPAddress.Parse(TextBox1.Text)
'sendport = Int32.Parse(TextBox2.Text)
'ipend = New IPEndPoint(ipadress, sendport)
Try
sendudp.JoinMulticastGroup(ipadress)
MessageBox.Show("启动完成!")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub