Public Class Form1 Dim Thread As New System.Threading.Thread(AddressOf Receive) Dim Udp As New System.Net.Sockets.UdpClient(6000) '受信ポートの番号 Dim IpEndPoint As New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0) Dim Sentence As String = "" Dim Flag As Boolean = True Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Timer1.Enabled = True Thread.Start() Udp.Connect("「ホストネーム」", 6000) End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Dim Send As [Byte]() = System.Text.Encoding.Default.GetBytes("「送信する文」") Udp.Send(Send, Send.Length) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Enabled = False If Sentence = "" Then Else MsgBox(Sentence & Chr(13) & Now, 0, "メッセージが届きました") Sentence = "" End If Timer1.Enabled = True End Sub Private Sub Receive() Do Dim Receive As [Byte]() = UdpClient.Receive(IpEndPoint) Dim MessageData As String = System.Text.Encoding.Default.GetString(Receive) Sentence = MessageData Loop While (Flag) End Sub End Class