'緩沖區(qū)長度
創(chuàng)新互聯(lián)公司專注于酉陽土家族苗族企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),商城開發(fā)。酉陽土家族苗族網(wǎng)站建設(shè)公司,為酉陽土家族苗族等地區(qū)提供建站服務(wù)。全流程按需定制網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
Const BufLen As Integer=800
'包發(fā)送間隔
Const Interval As Integer=62
'緩沖區(qū)
Dim buf As Byte()=Nothing
'遠(yuǎn)程(目的)網(wǎng)絡(luò)端點(diǎn)
Dim remoteep As IPEndPoint=Nothing
'如果你已將s定義為類的成員變量(實(shí)例或共享),注釋掉下面這句
Dim s As UdpClient=Nothing
Dim willread As Integer
Try
buf=New Byte(BufLen-1) {}
s=New UdpClient()
' TextBox1.Text包含遠(yuǎn)程(目的)主機(jī)的IP地址
' TextBox2.Text包含遠(yuǎn)程(目的)主機(jī)的端口號(hào)
remoteep=New IPEndPoint(IPAddress.Parse(Trim(TextBox1.Text)),CInt(TextBox2.Text))
' Label2.Text包含要發(fā)送的文件的路徑
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
DatagramSocket用于接收和發(fā)送UDP的Socket實(shí)例。該類有3個(gè)構(gòu)造函數(shù):DatagramSocket():通常用于客戶端編程,它并沒有特定監(jiān)聽的端口,僅僅使用一個(gè)臨時(shí)的。程序會(huì)讓操作系統(tǒng)分配一個(gè)可用的端口。DatagramSocket(int port):創(chuàng)建實(shí)例,并固定監(jiān)聽Port端口的報(bào)文。通常用于服務(wù)端。
服務(wù)器先進(jìn)行
Bind ()綁定服務(wù)器的端口
然后BeginReceive接受客戶端發(fā)送的數(shù)據(jù)
客戶端Bind ()綁定客戶端接受和發(fā)送數(shù)據(jù)的端口
SendTo()來發(fā)送數(shù)據(jù)就可以
不需要進(jìn)行BeginConnect,因?yàn)閁DP不需要連接
private void MyPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
public static boolean isNumeric(String str){
if(str.matches("http://d*"){
return true;
}else{
return false;
}
}