Hye, I have been task to creat a UDP file transfer using Visual Basic 2019.. i can transfer small files below 64kbytes but the requirement is bigger than that.. How to modify this code for it to be able to transfer larger files atleast 1Mbytes.
below is the client and server coding.
Client : - Imports System.Net.Sockets
-
Imports System.Text
-
Imports System.IO
-
Imports System.Net
-
-
Public Class frmClient
-
Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
-
-
Try
-
Dim udpClient As UdpClient = New UdpClient(txtIP.Text, Convert.ToInt32(txtPort.Text))
-
Dim fStream As FileStream
-
-
Dim sendPacket() As Byte
-
fStream = New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
-
ReDim sendPacket(fStream.Length)
-
fStream.Read(sendPacket, 0, fStream.Length)
-
-
Dim str As String = OpenFileDialog1.SafeFileName + " (" + fStream.Length.ToString + " bytes). Do you agree?"
-
udpClient.Send(Encoding.UTF8.GetBytes(str), str.Length)
-
-
Dim receivedPacket(5000) As Byte
-
-
udpClient.Client.ReceiveTimeout = 6000
-
receivedPacket = udpClient.Receive(Nothing)
-
If Encoding.UTF8.GetString(receivedPacket) = "YES" Then
-
udpClient.Send(sendPacket, sendPacket.Length)
-
udpClient.Client.ReceiveTimeout = 1000
-
receivedPacket = udpClient.Receive(Nothing)
-
If Encoding.UTF8.GetString(receivedPacket) = "SUCCESS" Then
-
MsgBox("File transfer success.")
-
Else
-
MsgBox("File transfer fail.")
-
End If
-
Else
-
MsgBox("Server rejects file transfer request.")
-
End If
-
-
fStream.Close()
-
udpClient.Close()
-
-
Catch ex As Exception
-
Console.WriteLine(ex.Message)
-
End Try
-
End Sub
-
-
Private Sub btnBrowse_Click(sender As Object, e As EventArgs) Handles btnBrowse.Click
-
Dim result As DialogResult = OpenFileDialog1.ShowDialog()
-
-
If result = Windows.Forms.DialogResult.OK Then
-
txtFile.Text = OpenFileDialog1.FileName
-
End If
-
-
End Sub
-
-
Private Sub frmClient_Load(sender As Object, e As EventArgs) Handles MyBase.Load
-
-
End Sub
-
-
End Class
Server: - Imports System.Net.Sockets
-
Imports System.Text
-
Imports System.IO
-
Imports System.Net
-
-
Public Class frmServer
-
Private Sub btnListen_Click(sender As Object, e As EventArgs) Handles btnListen.Click
-
-
Dim udpServer As UdpClient = New UdpClient(Convert.ToInt32(txtPort.Text))
-
Dim remoteEP As IPEndPoint = New IPEndPoint(IPAddress.Any, Convert.ToInt32(txtPort.Text))
-
Try
-
Dim receivedPacket(5000) As Byte
-
-
btnListen.Enabled = False
-
txtPort.ReadOnly = True
-
Me.Text = "Server - Listening"
-
-
udpServer.Client.ReceiveTimeout = 3000
-
receivedPacket = udpServer.Receive(remoteEP)
-
-
Dim res As MsgBoxResult = MsgBox(remoteEP.ToString +
-
" requests to transfer " +
-
Encoding.UTF8.GetString(receivedPacket), MsgBoxStyle.YesNo + MsgBoxStyle.Exclamation, "Message")
-
If res = MsgBoxResult.Yes Then
-
udpServer.Send(Encoding.UTF8.GetBytes("YES"), 3, remoteEP)
-
receivedPacket = udpServer.Receive(remoteEP)
-
Dim res2 As DialogResult = SaveFileDialog1.ShowDialog()
-
If res2 = Windows.Forms.DialogResult.OK Then
-
Dim fStream As FileStream = New FileStream(SaveFileDialog1.FileName, FileMode.Create, FileAccess.Write)
-
fStream.Write(receivedPacket, 0, receivedPacket.Length)
-
fStream.Close()
-
udpServer.Send(Encoding.UTF8.GetBytes("SUCCESS"), 7, remoteEP)
-
Else
-
udpServer.Send(Encoding.UTF8.GetBytes("FAIL"), 4, remoteEP)
-
End If
-
ElseIf res = MsgBoxResult.No Then
-
udpServer.Send(Encoding.UTF8.GetBytes("NO"), 2, remoteEP)
-
End If
-
-
udpServer.Close()
-
btnListen.Enabled = True
-
txtPort.ReadOnly = False
-
Me.Text = "Server"
-
-
Catch ex As Exception
-
Console.WriteLine(ex.Message)
-
udpServer.Close()
-
btnListen.Enabled = True
-
txtPort.ReadOnly = False
-
Me.Text = "Server"
-
End Try
-
-
End Sub
-
-
Private Sub frmServer_Load(sender As Object, e As EventArgs) Handles MyBase.Load
-
-
End Sub
-
End Class
0 2647 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Oren nizri |
last post by:
i need to create new microsoft outlook mail profile by using visual basic...
|
by: Pankajmani das |
last post by:
Dear sir
I am trying to open a word file using Visual Basic Commad. But I am failed. So, please guid me to open a perticular word or another file.
Note: I know how to open a file using common...
|
by: Danakmj |
last post by:
I developed a program using visual basic 6.0. I want to create a setup program that has an agreement page (i.e. it has two buttons ,I agree and I don’t agree buttons, so that if a user does not agree...
|
by: sena0112 |
last post by:
Hi, I'm a beginner in visual basic and programming. My programme needs to let the user browse for a text file and when the user press a command button, the programme will list out the text file into...
|
by: Edward1 |
last post by:
Hi! I am a newbie to programming, I am tryin to build a database application using visual basic .net and Ms Access, right now I am unable to update the Ms Access Database from visual basic. can...
|
by: ashokbio |
last post by:
I want to create an associative array, similar to PERL language, using Visual Basic 6.
Example: Using PERL
%A = ("A"=>"Apple","B"=>"Banana");
i.e., A is associated to the word Apple and B...
|
by: vikas000000a |
last post by:
Hi all,
I need to know how can I create a PDF file using visual basic. If somebody can tell me the step-by-step procedure for that, I will be very thankful. Actually, I have researched and tried...
|
by: Johnny Wong |
last post by:
Hi, I am new to visual basic.
In my vb system, there is a dynamic datagrid to represent different reocrds in our database. Today I am gonna export the data to Excel file. I found most examples code...
|
by: paolo71 |
last post by:
I have attached the source code written in Visual Basic 6 and I can not translate it in Visual 10 Express, I tried with different translators and even by hand, I modified the parameters that did not...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
| |