| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 930 人关注过本帖
标题:菜鸟求助——多播错误处理
只看楼主 加入收藏
abcjia
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-1-22
收藏
 问题点数:0 回复次数:1 
菜鸟求助——多播错误处理

如题


http://www.blueshop.com.tw/board/show.asp?subcde=BRD20051107142346OYO&fumcde=FUM20050124191756KKC&rplcnt=1



Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class Form1
Inherits System.Windows.Forms.Form

Dim intPort As Integer
Dim strAddress As String
Dim GroupEP As IPEndPoint
Dim SendUdp As New UdpClient

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents btnSend As System.Windows.Forms.Button
Friend WithEvents txtMessage As System.Windows.Forms.TextBox
Friend WithEvents txtResult As System.Windows.Forms.TextBox
Friend WithEvents btnStart As System.Windows.Forms.Button
Friend WithEvents txtIP As System.Windows.Forms.TextBox
Friend WithEvents txtPort As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnStart = New System.Windows.Forms.Button
Me.txtIP = New System.Windows.Forms.TextBox
Me.txtPort = New System.Windows.Forms.TextBox
Me.txtResult = New System.Windows.Forms.TextBox
Me.txtMessage = New System.Windows.Forms.TextBox
Me.btnSend = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'btnStart
'
Me.btnStart.Location = New System.Drawing.Point(456, 24)
Me.btnStart.Name = "btnStart"
Me.btnStart.Size = New System.Drawing.Size(144, 32)
Me.btnStart.TabIndex = 0
Me.btnStart.Text = "启动"
'
'txtIP
'
Me.txtIP.Location = New System.Drawing.Point(24, 32)
Me.txtIP.Name = "txtIP"
Me.txtIP.Size = New System.Drawing.Size(184, 21)
Me.txtIP.TabIndex = 1
Me.txtIP.Text = "230.100.100.100"
'
'txtPort
'
Me.txtPort.Location = New System.Drawing.Point(224, 32)
Me.txtPort.Name = "txtPort"
Me.txtPort.Size = New System.Drawing.Size(184, 21)
Me.txtPort.TabIndex = 2
Me.txtPort.Text = "36000"
'
'txtResult
'
Me.txtResult.Location = New System.Drawing.Point(16, 80)
Me.txtResult.Multiline = True
Me.txtResult.Name = "txtResult"
Me.txtResult.Size = New System.Drawing.Size(584, 216)
Me.txtResult.TabIndex = 3
Me.txtResult.Text = "TextBox3"
'
'txtMessage
'
Me.txtMessage.Location = New System.Drawing.Point(16, 312)
Me.txtMessage.Name = "txtMessage"
Me.txtMessage.Size = New System.Drawing.Size(392, 21)
Me.txtMessage.TabIndex = 4
Me.txtMessage.Text = "TextBox4"
'
'btnSend
'
Me.btnSend.Location = New System.Drawing.Point(464, 312)
Me.btnSend.Name = "btnSend"
Me.btnSend.Size = New System.Drawing.Size(128, 24)
Me.btnSend.TabIndex = 5
Me.btnSend.Text = "传送"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(472, 360)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(120, 24)
Me.Button1.TabIndex = 6
Me.Button1.Text = "Button1"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(16, 352)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(240, 21)
Me.TextBox1.TabIndex = 7
Me.TextBox1.Text = "TextBox1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(624, 574)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.btnSend)
Me.Controls.Add(Me.txtMessage)
Me.Controls.Add(Me.txtResult)
Me.Controls.Add(Me.txtPort)
Me.Controls.Add(Me.txtIP)
Me.Controls.Add(Me.btnStart)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

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

End Sub

Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim bteSendDate() As Byte
Try
bteSendDate = Encoding.Unicode.GetBytes(txtMessage.Text)
SendUdp.Send(bteSendDate, bteSendDate.Length, GroupEP)
txtResult.text = txtResult.text + txtMessage.Text + vbCrLf

txtMessage.Text = ""
txtMessage.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub


Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
Dim GroupIP As IPAddress
Dim intSendPort As Integer

GroupIP = IPAddress.Parse(txtIP.Text)
intSendPort = Integer.Parse(txtPort.Text)
GroupEP = New IPEndPoint(GroupIP, intSendPort)
SendUdp.JoinMulticastGroup(GroupIP, 12)

MessageBox.Show("启动完成!")
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sHostName As String
Dim i As Integer
sHostName = Dns.GetHostName()
Dim ipE As IPHostEntry = Dns.GetHostByName(sHostName)
Dim IpA() As IPAddress = ipE.AddressList
For i = 0 To IpA.GetUpperBound(0)
TextBox1.Text = ("IP Address " & i.ToString & " " & IpA(i).ToString)
Next
End Sub
End Class

搜索更多相关主题的帖子: System Dim Imports 
2006-01-22 01:07
cnmagic
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-1-28
收藏
得分:0 
我才是菜鸟呢,看不懂你到底要干什么?是什么意思。

Me.菜鸟 = True
2006-02-09 15:11
快速回复:菜鸟求助——多播错误处理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014765 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved