Use UdpClient to receive a file : UdpClient « Socket Network « VB.Net Tutorial






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

Public Class Tester
    Public Shared Sub Main

        Try
            Dim bteDataAccept() As Byte
            Dim strdataAccept As String = ""
            Dim myEndPoint As New IPEndPoint(IPAddress.Parse("127.0.0.1"), 12345)
            Dim myByte(36000) As Byte

            Dim myUdpClient As UdpClient = New UdpClient(12345)
            myByte = myUdpClient.Receive(Nothing)

            Dim myFileStream As FileStream = New FileStream("test.txt", FileMode.Create, FileAccess
.Write)
            myFileStream.Write(myByte, 0, myByte.Length)

            myFileStream.Close()
            myUdpClient.Close()

        Catch e As Exception

            Console.WriteLine(e.ToString )
        End Try
    End Sub

End Class








22.15.UdpClient
22.15.1.Create Udp Connection using UdpClient
22.15.2.Use UdpClient to send message
22.15.3.Use UdpClient to receive data
22.15.4.Use UdpClient to send a file
22.15.5.Use UdpClient to receive a file