VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • [VB.NET]询异步socket通信完善的例子


 


	
  1.  
    Imports System.Net
  2.  
    Imports System.Text.Encoding
  3.  
  4.  
    Public Class Form1
  5.  
    Dim publisher As New Sockets.UdpClient(0)
  6.  
    Dim subscriber As New Sockets.UdpClient(2000)
  7.  
  8.  
  9.  
  10.  
    Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  11.  
    Try
  12.  
    Dim ep As IPEndPoint = New IPEndPoint(IPAddress.Any, 0)
  13.  
    Dim rcvbytes() As Byte = subscriber.Receive(ep)
  14.  
    TextBox4.Text = ASCII.GetString(rcvbytes)
  15.  
    Catch ex As Exception
  16.  
    End Try
  17.  
    End Sub
  18.  
  19.  
    Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  20.  
    subscriber.Client.ReceiveTimeout = 100
  21.  
    subscriber.Client.Blocking = False
  22.  
    End Sub
  23.  
  24.  
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  25.  
    publisher.Connect(TextBox1.Text, TextBox2.Text)
  26.  
    Dim sendbytes() As Byte = ASCII.GetBytes(TextBox3.Text)
  27.  
    publisher.Send(sendbytes, sendbytes.Length)
  28.  
    End Sub
  29.  
    End Class
  30.  
 

 

 

 

 

 

 

 

 


相关教程